将后退按钮添加到 UITabBarController 内的 UINavigationController
Adding Back button to UINavigationController inside UITabBarController
UITabBarController
从 UINavigationController
加载为 rootViewController
。我有 6 个 Tabs
、FifthViewController
和 SixthViewController
位于 More
选项卡下,他们按 DetailsViewController
显示详细信息。我无法在 DetailsViewController
中显示返回按钮以返回到 ParentViewController。我尝试了以下所有选项,但其中 none 有效。
我正在从 Storyboard
加载 UITabBarController
作为初始视图控制器,并从 Storyboard
加载 FifthViewController
和 SixthViewController
。在 FifthViewController
我设置 Header
-(void)viewWillAppear:(BOOL)animated
{
self.title = @"Alerts" ;
self.tabBarController.title = @"Alerts" ;
}
在DetailsViewController
我设置Header
-(void)viewWillAppear:(BOOL)animated
{
//I tired all the below options to show back button
}
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.tabBarController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.tabBarController.navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
我哪里做错了?
根据您的描述,您的设置不正确。
UITabBarController
应该是应用程序的 rootViewController
。每个选项卡应该是 UINavigationController
。每个导航控制器都应该为每个选项卡设置适当的根视图控制器。
标签栏控制器本身不应该在导航控制器中。
您不应设置任何导航项的 backBarButtonItem
。
使用我描述的设置,每个选项卡都有自己独特的导航。例如,用户可以在选项卡二上,然后前进到该选项卡中的下一个视图控制器。标签将保持可见。现在用户可以转到任何选项卡,然后 return 转到第二个选项卡,并且仍然在该选项卡的第二个视图控制器上。
您需要 UINavigationController
作为 UITabBarController
的 子项 ,如果您希望它在带有导航堆栈和后退按钮的选项卡中运行.
UITabBarController
从 UINavigationController
加载为 rootViewController
。我有 6 个 Tabs
、FifthViewController
和 SixthViewController
位于 More
选项卡下,他们按 DetailsViewController
显示详细信息。我无法在 DetailsViewController
中显示返回按钮以返回到 ParentViewController。我尝试了以下所有选项,但其中 none 有效。
我正在从 Storyboard
加载 UITabBarController
作为初始视图控制器,并从 Storyboard
加载 FifthViewController
和 SixthViewController
。在 FifthViewController
我设置 Header
-(void)viewWillAppear:(BOOL)animated
{
self.title = @"Alerts" ;
self.tabBarController.title = @"Alerts" ;
}
在DetailsViewController
我设置Header
-(void)viewWillAppear:(BOOL)animated
{
//I tired all the below options to show back button
}
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.tabBarController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
self.tabBarController.navigationController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] ;
我哪里做错了?
根据您的描述,您的设置不正确。
UITabBarController
应该是应用程序的 rootViewController
。每个选项卡应该是 UINavigationController
。每个导航控制器都应该为每个选项卡设置适当的根视图控制器。
标签栏控制器本身不应该在导航控制器中。
您不应设置任何导航项的 backBarButtonItem
。
使用我描述的设置,每个选项卡都有自己独特的导航。例如,用户可以在选项卡二上,然后前进到该选项卡中的下一个视图控制器。标签将保持可见。现在用户可以转到任何选项卡,然后 return 转到第二个选项卡,并且仍然在该选项卡的第二个视图控制器上。
您需要 UINavigationController
作为 UITabBarController
的 子项 ,如果您希望它在带有导航堆栈和后退按钮的选项卡中运行.