调用Facebook登录后,removeFromSuperview无法正常工作

时间:2015-08-18 01:45:08

标签: objective-c uiview uiviewcontroller

我知道这里有很多其他答案,但我似乎无法找到适用于我特定问题的答案。我有一个视图控制器,我检查Facebook会话。如果没有活动会话,我运行以下用户可以选择使用Facebook登录:

    FacebookViewController *goFacebook = [[FacebookViewController alloc]init];
    goFacebook = [self.storyboard instantiateViewControllerWithIdentifier:@"Facebook"];
    [self.navigationController pushViewController:goFacebook animated:NO];

登录后,用户返回到我运行的Facebook视图控制器:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; 

[self.navigationController popViewControllerAnimated:YES]; ///to return user to original view.

一旦返回到原始视图控制器,我的代码就会运行以填充tableview,其中我有一个UIView(searchView),其中添加了以下代码:

    self.loadIndicator =  [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    self.loadIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    self.loadIndicator.hidesWhenStopped = YES;

    self.loadingText = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, 275, 60)];
    self.loadingText.text = @"Loading your items...";
    self.loadingText.textColor = [UIColor whiteColor];
    self.loadingText.font = [UIFont fontWithName:@"Gill Sans" size:24];
    self.loadingText.backgroundColor = [UIColor clearColor];
    self.loadingText.numberOfLines = 0;
    self.loadingText.textAlignment = NSTextAlignmentCenter;

    searchView = [[UIView alloc]initWithFrame:CGRectMake(240, 300, 300, 60)];
    searchView.alpha = 1.0;
    searchView.opaque = YES;
    searchView.backgroundColor = [UIColor colorWithRed:(36.0/255.0) green:(147.0/255.0) blue:(195.0/255.0) alpha:1];
    searchView.layer.cornerRadius = 10.0;

    [m_tableView2 addSubview:searchView];        
    [searchView addSubview:self.loadingText];
    [searchView addSubview:self.loadIndicator];
    [self.loadIndicator startAnimating];

我试图删除:

[self.searchView removeFromSuperview];

不会删除searchView。也不是:

[self.searchView performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:NO];

我确定我会受到重创并因此而被投票,但我没有找到解决问题的正确答案。不过,我们非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在主线程上调用removeFromSuperView我希望它能正常工作。

相关问题