mve*_*xel 8 iphone uinavigationcontroller
我有一个应用程序有一个UINavigationController推进UITabBarController视图.这UITabBarController有四个选项卡,其中一个显示自定义UIViewController,一个实例EventInformationViewController.此自定义视图控制器中的按钮依次将另一个自定义视图控制器推EventRatingAddViewController入视图.此视图控制器中的操作应调用EventInformationViewController实例中的方法.以下代码使应用程序崩溃:
// get the index of the visible VC on the stack
int myIindex = [self.navigationController.viewControllers indexOfObject:self.navigationController.visibleViewController];
// get a reference to the previous VC
EventInformationViewController *prevVC = (EventInformationViewController *)[self.navigationController.viewControllers objectAtIndex:myIindex - 1];
[prevVC performSelector:@selector(rateCurrentEvent:)];
Run Code Online (Sandbox Code Playgroud)
我认为viewControllers属性在导航堆栈上保留了所有VC的数组,因此当前可见的减去索引的索引应指向将当前可见VC推入视图的VC.相反,它似乎指向我UITabBarController:
-[UITabBarController rateCurrentEvent:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
具体是什么,更重要的是,如何获得指向VC的指针,该指针将当前可见的VC推入视图?
编辑:我最终创建了一个委托协议,EventRatingAddViewController并指定EventInformationViewController为委托.这很好用 - 我仍然认为应该有一种方法来通过导航堆栈访问推送VC.
我很确定这UITabBarController确实推动了你当前的视图控制器,但你正在寻找的是其中一个UITabBarController选项卡的视图控制器,在推动你的视图控制器UITabBarController时可见UITabBarController的视图控制器在导航堆栈上.可能这UITabBarController会将您的视图控制器推到堆栈上,因为它被可见选项卡的视图控制器告知它,所以它会是这样的:[self.tabBarController.navigationController pushViewController:someViewController];.
找出UITabBarController视图控制器被推入堆栈时显示的视图控制器的方法是使用.selectedViewController属性,这样会产生如下所示:
// get the index of the visible VC on the stack
int currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
// get a reference to the previous VC
UITabBarController *prevVC = (UITabBarController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex - 1];
// get the VC shown by the previous VC
EventInformationViewController *prevShownVC = (EventInformationViewController *)prevVC.selectedViewController;
[prevShownVC performSelector:@selector(rateCurrentEvent:)];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8610 次 |
| 最近记录: |