Combining Navigation Controller with Tab Bar Controller(结合导航控制器和标签栏控制器)
问题描述
正如我在标题中提到的,我想将 Navigation Controller 添加到我已经有 Tab Controller 的应用程序中.因此,尝试在 页.无论如何,有些不对劲.UINavigationController 正在寻找一个空白页面,即使有一个视图和一些库.
As I mentioned in the title, I want to add Navigation Controller to my application which already has a Tab Controller. So trying to do the staff something like on this page. Anyway, something is wrong. UINavigationController is looking a blank page, even if has a view and some libraries.
让我从头开始:
在我的 AppDelegate 中,我正在设置标签栏控制器,如下所示:
In my AppDelegate, I'm setting tab bar controllers like this:
@interface MYAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
这是.m文件:
@implementation MYAppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    application.applicationSupportsShakeToEdit = YES;
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UINavigationController *viewController1 = [[[MYMainViewController alloc] init] initWithNibName: @"MYMainViewController" bundle:nil];
    UIViewController *viewController2 = [[[MYPageViewController alloc] init] initWithNibName:@"MYPageViewController" bundle:nil];
    UIViewController *viewController3 = [[[MYSearchViewController alloc] init] initWithNibName:@"MYSearchViewController" bundle:nil];
    UIViewController *viewController4 = [[[MYPersonViewController alloc] init] initWithNibName:@"MYPersonViewController" bundle:nil];
    // Initialize tabBarController and add ViewControllers
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, 
        viewController3, viewController4, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
然后,这里是 MYMainViewController 实现,它是一个 UINavigationController:
Then, here is MYMainViewController implementaion which is a UINavigationController:
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@", [self navigationController]); // Logging null
}
我的 .xib 文件有一个 UINavigationController 并且其中有一个视图.尽管如此,当我使用该应用程序时,有空白页面和无标题导航栏.我做错了什么?
My .xib file has a UINavigationController and and there is a view in it. Althought it, when I worked the app, there is blank page and untitled navigation bar. What am I doing wrong?
如果我可以看到我的视图的内容,我想使用后退按钮在两个视图控制器之间导航.
If I could see the content of my view, I want to navigate between two view controllers by using back button.
任何帮助或方法对我来说都很棒.
Any help or approach would be great for me.
推荐答案
尝试从xib中移除导航控制器,使其只有视图控制器,然后以编程方式初始化导航控制器:
Try to remove navigation controller from xib, so it only have view controller, then initialize navigation controller programatically:
UIViewController *tmpViewController1 = [[[YourViewController alloc] init] initWithNibName:@"YourViewController" bundle:nil];
 UINavigationController *viewController1 =  [[UINavigationController alloc] initWithRootViewController:tmpViewController1];
                        这篇关于结合导航控制器和标签栏控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:结合导航控制器和标签栏控制器
				
        
 
            
        基础教程推荐
- Play 商店的设备兼容性问题 2022-01-01
 - iOS - UINavigationController 添加多个正确的项目? 2022-01-01
 - 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
 - navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
 - Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
 - UIImage 在开始时不适合 UIScrollView 2022-01-01
 - 如何将图像从一项活动发送到另一项活动? 2022-01-01
 - SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
 - 如何比较两个 NSDate:哪个是最近的? 2022-01-01
 - Android Volley - 如何动画图像加载? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				