Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set title #3

Closed
fatuhoku opened this issue Nov 3, 2014 · 5 comments
Closed

Cannot set title #3

fatuhoku opened this issue Nov 3, 2014 · 5 comments

Comments

@fatuhoku
Copy link

fatuhoku commented Nov 3, 2014

I've got a storyboard set up, linked to a XIB:

screen shot 2014-11-03 at 22 52 15
screen shot 2014-11-03 at 22 52 44

I'm trying to override the title given in the storyboard programmatically from the view controller but not having much luck:

@implementation LSPopoverViewController

// ...

-(void)viewDidAppear:(BOOL)animated {
    NSAssert(self.navigationItem, @"Expected navigation item to have a value");

    NSLog(@"Presenting controller: %@", self.presentingViewController);
    NSLog(@"Navigation controller's item: %@", self.navigationController.navigationItem);
    NSLog(@"Navigation hidden?: %d", self.navigationController.navigationBarHidden);

    self.title = @"Popover View Controller";
    self.navigationItem.title = @"Popover View Controller";
    self.navigationController.navigationItem.title = @"Popover View Controller";
}

@end

screen shot 2014-11-03 at 22 53 54

WRONG TITLE still shows. How comes?

@fatuhoku
Copy link
Author

fatuhoku commented Nov 3, 2014

@yoiang
Copy link
Member

yoiang commented Nov 3, 2014

So the issue here is that the navigation item you need to address is only actually relative to the view immediately contained in the UINavigationViewController, ie the StoryboardXIBController. If you grab the StoryboardXIBController in your sub-ViewController you should be able to assign its navigation item properly in your sub-ViewController.

LSPopoverViewController.h

@interface LSPopoverViewController : UIViewController<StoryboardXibContainedController>
...

LSPopoverViewController.m

...
- (void)storyboardXibLoadedBy:(StoryboardXibController *)storyboardXibController
{
    storyboardXibController.navigationItem.title = @"Popover View Controller";
}
...

Or other than assign it directly in storyboardXibLoadedBy hold a weak reference to the StoryboardXibController instance and set the title when you know what the title should be.

Let me know if this works!

This seems like a pretty common thing that people will want to do, I'll think about a simpler way to get the navigation item of the StoryboardXIBController.

@fatuhoku
Copy link
Author

fatuhoku commented Nov 3, 2014

Hmmm. It's definitely very useful. I think I could work with that — it's a pretty leaky abstraction though, since the View Controller will now need to know about the fact that it's been loaded by a StoryboardXibController.

UIViewController has a few contractual obligations that need to be met. What's stopping the navigation controller be set onto the navigationController and navigationItem properties? It's more complicated than that, isn't it? :P

@yoiang
Copy link
Member

yoiang commented Nov 3, 2014

I agree completely, I'll try to think of a cleaner solution, again let me know if you come up with something!

Yea, UIViewControllers in general are very contradictory, in no small part by their exposure and access to the navigation view and items ;)

@yoiang yoiang closed this as completed Nov 4, 2014
@yoiang
Copy link
Member

yoiang commented Nov 4, 2014

Created issue #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants