开发者

Selecting index of tabBarController and passing data

开发者 https://www.devze.com 2023-02-06 05:23 出处:网络
I wan开发者_如何学Pythont to select the UIViewController at index 0 of my tabbarcontroller while passing data to it. It seems I am accessing the UINavigationController instead. Anyone know why this oc

I wan开发者_如何学Pythont to select the UIViewController at index 0 of my tabbarcontroller while passing data to it. It seems I am accessing the UINavigationController instead. Anyone know why this occurs?

SearchViewController *search = (SearchViewController *)[self.tabBarController.viewControllers objectAtIndex:0];
[search initWithText:@"This is a test"];

[[self.tabBarController.viewControllers objectAtIndex:1] pushViewController:search animated:NO];

// Also receive the error using this:

self.tabBarController.selectedViewController = search;

Error:

-[UINavigationController initWithText:]: unrecognized selector sent to instance 


Wow, now I feel silly. This worked.

UINavigationController *navController = [self.tabBarController.viewControllers objectAtIndex:0];
SearchViewController *search = [navController.viewControllers objectAtIndex:0];
[search initWithText:@"This is a test"];
self.tabBarController.selectedViewController = navController;
0

精彩评论

暂无评论...
验证码 换一张
取 消