Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c PoptorootViewController初始化在shouldSelectViewController UITabBarControllerDelegate方法的上下文中执行不正确_Objective C_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Objective c PoptorootViewController初始化在shouldSelectViewController UITabBarControllerDelegate方法的上下文中执行不正确

Objective c PoptorootViewController初始化在shouldSelectViewController UITabBarControllerDelegate方法的上下文中执行不正确,objective-c,uinavigationcontroller,uitabbarcontroller,Objective C,Uinavigationcontroller,Uitabbarcontroller,我已为我的UITabBarController设置了一个委托,并使用以下委托方法: - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { [self.navigationController popToRootViewControllerAnimated: YES];

我已为我的UITabBarController设置了一个委托,并使用以下委托方法:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {    
        [self.navigationController popToRootViewControllerAnimated: YES];
        return NO;
}
方法激发,在上下文中,我将一到两个级别转换为表视图。根视图控制器显示正确,但是导航栏没有重置,并且仍然有一个从一个或两个级别返回到表视图的后退按钮

上面的委托方法是我试图在我的应用程序中执行的一种简化形式,但仍然存在问题。在我的应用程序中,我需要在返回到原始选项卡时显示根视图,因此我在离开前尝试弹出到根视图

这说明了一个时间滞后问题,但在我的案例中,情况似乎并非如此。在执行shouldSelectViewController和导航栏后退按钮之前,我可以等多久就等多久

代表是:

@interface BasicPlaceItemComment : UIViewController<UIAlertViewDelegate, UITabBarControllerDelegate> {
    // data members ommitted
} 

这是我从中派生所有表视图的类。

您确定该方法位于正确的上下文中吗? 谁遵守塔巴德勒门?如果是AppDelegate,则self.navigationController可能为零。 如果您使用的是选项卡栏,并且您有多个导航控制器,那么您可能在错误的控制器上调用popToRootViewController。 尝试插入以下内容:

NSLog(@"%@", self.navigationController);
在方法的开头,确保获得正确导航控制器的地址


发布更多的代码可能会有所帮助。

问题似乎是我在对UINavigationController进行子类化以解决另一个问题。当我删除这个子类时,问题就消失了。也就是说,当我在没有子类UINavigationController的情况下使用popToRootViewController时,返回按钮不再混乱。然而,这又提出了另一个问题。为了解决中所述的问题,我对UINavigationController进行了子类化

使用导航栏和标签栏,我希望能够显示一条消息,您确定要退出吗?当显示视图中的某些数据在离开该视图之前发生更改,并且可能取消离开该视图时,按下“后退”按钮或其他选项卡时发出警报

因此,虽然这只是部分答案,但我的问题仍然存在。当用户键入后退按钮或其他选项卡时,我仍然需要一种方法来获得控制权。因此,我似乎需要: 1对于UINavigationBarDelegate方法,意味着有一个不同于UINavigationController的委托应为OPITEM,或 2一些方法可以将UINavigationController子类化,但不会像我单击选项卡并调用popToRootViewController时当前所发生的那样将后退按钮弄乱

还有什么想法

更多关于11/3/12的信息

导致问题的不是UINavigationController子类化本身。我无意中从委托方法返回了NO

// This method returns true when the navigation bar should pop an item
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
当我做popToRootViewController的时候。我现在在UINavigationController子类中有一个方法:

- (void) popToRoot {
    regularPop = YES;
    [self popToRootViewControllerAnimated: YES];
}

这导致shouldPopItem返回YES,我使用它代替popToRootViewController。我的大部分问题都解决了

代表的班级是:谢谢!我现在明白了。回答如下!