2014-11-22 36 views
0

我正在开发一个响应Parse推送通知的应用程序。在应用程序的某个时候,我想按下另一个用户发送的推送通知,这应该会将我重定向到TabBarController中的第三个ViewController(选项卡),并且我想在该选项卡中显示一个视图。appDelegate中的块内调用方法

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 
    if (!error && [PFUser currentUser]) { 
     //Display the TabBarController 
     UIViewController *controller = [[UIViewController alloc] init]; 
     controller = [storyboard instantiateViewControllerWithIdentifier:@"TabBar"]; 
     self.window.rootViewController = controller; 
     [self.window makeKeyAndVisible]; 
     //Display the third tab 
     self.tabBarController = (TabBarViewController *)self.window.rootViewController; 
     self.tabBarController.delegate = (id)self; 
     self.tabBarController.selectedIndex = 2; 

     [self.tabBarController display]; 


    } 
    else{ 
     NSLog(@"%@", error); 
    } 

}];  

我查询差我来的通知和查询结束后,我想在我的TabBarContoller的视图控制器一个标签来显示用户的用户名的用户。 (但为了简单起见,我只想在第三个标签中显示一个视图)。

我试着在块外执行相同的代码行,并且它工作,但是由于某种原因,当我尝试在块内执行[self.tabBarController display]时,它不起作用。

我也试过:

__block TabBarViewController* blocksafeSelf = self.tabBarController; 

.... 

.... 

[blocksafeSelf display]; 

,但它没有工作!

我一直在寻找如何解决它的小时!任何帮助,将不胜感激。

回答

1

尝试把

dispatch_sync(dispatch_get_main_queue(), ^{ 
    [self.tabBarController display]; 
}); 

在你原来的方法,好像你正在做后台线程这可能会导致UI更新奇怪的事情发生

+0

其他试图把一切都在我刚才提到的块并看看是否有效,并从那里去 – Fonix 2014-11-22 14:48:27

+0

谢谢你的回复,但不幸的是它没有工作。如果我把所有内容都放在屏幕上,应用程序就会出现黑屏并在一段时间后崩溃。我也尝试使用[self.tabBarController performSelectorOnMainThread:@selector(display)withObject:nil waitUntilDone:NO]但没有任何运气。 – RB12 2014-11-23 09:33:37

+0

我发现问题是什么!我有一行代码尝试提取数组对象的第一个索引(由于某个错误,它始终为零),并且出于某种原因它阻止了之后的任何行。我不知道这将是相关的添加,所以我从帖子中删除它。 – RB12 2014-11-23 17:29:10