[英]Combining Navigation Controller with Tab Bar Controller
As I mentioned in the title, I want to add Navigation Controller
to my application which already has a Tab Controller
. 正如我在标题中提到的,我想将
Navigation Controller
添加到已经有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. UINavigationController
看起来是一个空白页面,即使有一个视图和一些库。
Let me begin from the stracht: 让我从stracht开始:
In my AppDelegate
, I'm setting tab bar controllers like this: 在我的
AppDelegate
,我正在设置标签栏控制器,如下所示:
@interface MYAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
And here is .m file: 这是.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;
}
Then, here is MYMainViewController
implementaion which is a UINavigationController
: 然后,这是
MYMainViewController
实现,它是一个UINavigationController
:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@", [self navigationController]); // Logging null
}
My .xib file has a UINavigationController
and and there is a view in it. 我的.xib文件有一个
UINavigationController
,并且有一个视图。 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. 任何帮助或方法对我来说都很棒。
Try to remove navigation controller from xib, so it only have view controller, then initialize navigation controller programatically: 尝试从xib中删除导航控制器,因此它只有视图控制器,然后以编程方式初始化导航控制器:
UIViewController *tmpViewController1 = [[[YourViewController alloc] init] initWithNibName:@"YourViewController" bundle:nil];
UINavigationController *viewController1 = [[UINavigationController alloc] initWithRootViewController:tmpViewController1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.