简体   繁体   中英

navigation controller doesn't show up the view

PS: Please do not suggest me to go with the app delegate way as I will use that in the middle of my app views. Thanx.

I try to use a UINavigationController to display a UITableView like the settings app. So I am trying to start step by step. So far, I try to show up a view contained in a view controller in the navigation stack. But I am missing something somewhere.

Here is my relevant code:

.h file:

@interface ViewController : UINavigationController{



    UINavigationController *navigationController;
    UIViewController *viewController;
}



@property(nonatomic, strong)IBOutlet UINavigationController *navigationController;
@property(nonatomic, strong)IBOutlet UIViewController *viewController;
@end

.m file :

@implementation ViewController
@synthesize navigationController;
@synthesize viewController;

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Do any additional setup after loading the view, typically from a nib.

    self.viewController = [[UIViewController alloc]init];

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];


    [self.navigationController.view addSubview:self.viewController.view];


}

**The xib file:**

在此处输入图片说明

When I run the app, I am expecting to see the blue view, but all I see is the default blue navigation bar, without even the "Root View Controller" title message.

If you connect UI from IB, try to delete these line (delete alloc, init)

//  self.viewController = [[UIViewController alloc]init];
//  self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
//  [self.navigationController.view addSubview:self.viewController.view];

This link Should help you. You might want to go through this to shed better light on the problem you're having.

https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/Introduction/Introduction.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM