选择tabBarController的索引并传递数据

时间:2011-01-21 18:28:46

标签: ios uitabbarcontroller

我想在我的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 

1 个答案:

答案 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;