Simple Title not showing up in UINavigationController

后端 未结 3 555
广开言路
广开言路 2021-01-05 11:10

I have looked at all of the similar/related questions, but none either a) are exactly my problem or 2) the solutions just don\'t work.

In my appDelegate.m I have in

3条回答
  •  误落风尘
    2021-01-05 11:45

    Thanks believesInSanta, While I cannot find this explicitly stated in apple documentation anywhere, I have to go with this being the answer. UINavigationController doesn't have a title.

    To get the title to work, back in appDelegate.h I added:

    JCGTableViewController *tvc = [[JCGTableViewController alloc] init];
    JCGRootNavigationController *rnc = [[JCGRootNavigationController alloc] initWithRootViewController:tvc];
    self.window.rootViewController = rnc;
    

    Where JCGTableViewController is another subclass I added. As you can probably tell, it is a subclass of UITableViewController.

    In JCGTableViewController I overrode init to:

    -(instancetype) init {
    
        self = [super init];
        if(self) {
            self.title = @"TVC";
            self.view.backgroundColor = [UIColor lightGrayColor];
        }
    
        return self;
    }
    

    While I used a tableViewController, I imagine you can add any view to the NavigationController and set the properties that way. I will play around with that today.

    Thanks all!

提交回复
热议问题