我有一个模态segue,从视图控制器到标签栏控制器,它嵌入在表格视图中,如此截图所示:
http://cl.ly/image/1V1W3g0W3W1Z
http://f.cl.ly/items/1h0m1j0q3B0e0m3S2Z0v/Screen%20Shot%202014-06-01%20at%207.31.22%20PM.png
我想在登录屏幕和表格视图之间传递数据。我使用以下代码:
-(IBAction)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Enter App"]){
//Pass on username so that app can set everything up for that specific user
GamesListTableViewController *gamesList = (GamesListTableViewController *)segue.destinationViewController;
if ([segue.destinationViewController isKindOfClass:[GamesListTableViewController class]]) {
NSLog(@"ENTERING PROPER CLASS");
}
else{
NSLog(@"ENTERING WRONG CLASS");
}
gamesList.userID = self.userID;
}
}
由于最后一行代码,我的应用程序崩溃了。我检查了原因(正如你在上面的代码中看到的),原因是segue目的地不是GamesListTableViewController,但我假设的是标签栏控制器。如何解决这个问题?
答案 0 :(得分:1)
UITabbarController *tabController = (UITabbarController*) segue.destinationViewController;
UINavigationController *nav = (UINavigationController*) tabController.viewControllers[0]; // or some other nr
GamesListTableViewController *tvc = nav.topViewController;