我的应用程序中的选项卡视图存在很大问题。我的问题是我在标签栏中间使用了一个自定义 UIButton ,然后在我更改索引时手动调用了didSelectViewController
委托方法。UITabBarControllerDelegate
问题是,当我想检查已选择的视图控制器时,我没有得到正确的视图控制器实例。
代码:
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
UIViewController *tempController = [tabBarController.viewControllers objectAtIndex:2];
if (viewController == [tabBarController.viewControllers objectAtIndex:2]) //Never the same
{
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
NSLog(@"Popping to root");
}
}
我在这里调用该方法:
-(void) notifmethod{
UIViewController *cameraViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"cameraNavViewController"]; //Tried this
//CameraNavController *viewController = [[CameraNavController alloc] init];/And this
[self tabBarController:self didSelectViewController:cameraViewController]; //The call
NSLog(@"This called");
}
主要原因是popToRootViewControllerAnimated:NO
如果选择了某个视图控制器,我想这样做。感谢您的任何帮助!