组合导航控制器与制表条控制器 [英] Combining Navigation Controller with Tab Bar Controller
问题描述
正如我在标题中提到的,我想向我的应用程序添加 Navigation Controller
,该应用程序已经有一个 Tab控制器
。所以试图做这个工作人员像这个页面。无论如何,有什么不对。 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.
让我从stracht开始:
Let me begin from the stracht:
在我的 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
implementationaion这是一个 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];
这篇关于组合导航控制器与制表条控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!