0

我使用 uitabbar 为 ios 开发了一个应用程序。在标签栏中,我有一些 uitableview 导致一些 uiview。例如:

A:Tabbar 按钮 -> B:Table View -> C:View 相对于用户点击的表格视图的行

标签栏的正常行为是,如果我单击直到我已指示为“C”的视图,然后单击另一个标签栏按钮并单击返回我已指示为“A”的标签栏按钮,我发现打开了查看“C”而不是“B”(由标签栏按钮调用的表格视图)。现在我希望标签栏始终通向它的第一个视图(在这种情况下 B,即使用户单击直到 C)为了做到这一点,我在我的 appdelegate 中使用此代码,以确保它甚至具有相同的行为在“更多按钮”的情况下。

UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController;

if ([viewController isKindOfClass:[UINavigationController class]]) {
    [tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];
}
if (tabBarController2.selectedIndex < 4) {
    [tabBarController2.moreNavigationController popViewControllerAnimated:NO];
}

有时,当它尝试弹出时,应用程序崩溃。我究竟做错了什么?

线

[tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];

触发此警告“AppDelegate.m:27:10: 'UIViewController' 可能无法响应 'popToRootViewControllerAnimated:'”

4

2 回答 2

3

我建议您的一种方法是,在您的 UIView viewWillDisapear 方法中编写以下代码:

[self.navigationController popToRootViewControllerAnimated:NO];
于 2013-04-02T11:05:53.800 回答
1
popToRootViewControllerAnimated:

这是 UINavigationController 类的一个方法,您将它用于 UITabBarController,它是 UIViewController 的子类。

尝试:

[(UINavigationController *)tabBarController2.selectedViewController popToRootViewControllerAnimated:NO];
于 2013-04-02T10:02:31.203 回答