我想在我的tabbarcontroller的索引0处选择UIViewController,同时将数据传递给它。看来我正在访问UINavigationController。有人知道为什么会这样吗?
SearchViewController *search = (SearchViewController *)[self.tabBarController.viewControllers objectAtIndex:0];
[search initWithText:@"This is a test"];
[[self.tabBarController.viewControllers objectAtIndex:1] pushViewController:search animated:NO];
//也会收到错误:
self.tabBarController.selectedViewController = search;
错误:
-[UINavigationController initWithText:]: unrecognized selector sent to instance
答案 0 :(得分:4)
UINavigationController *navController = [self.tabBarController.viewControllers objectAtIndex:0];
SearchViewController *search = [navController.viewControllers objectAtIndex:0];
[search initWithText:@"This is a test"];
self.tabBarController.selectedViewController = navController;