views:

32

answers:

3

Hi all,

In my app, I'm presenting a modalviewcontroller as follows and I'm not able to change the navigationbar's title or any of its properties for that matter.

fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:@"fullListTopCompanies" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;
[submit release];


[self presentModalViewController:cntrol animated:YES];
[cntrol release];

I tried instantiating application delegate and assigning its navigationcontroller to local navigationcontroller instance but no use.

Somehow that navigationcontroller is not accessible. It can't be accessed by using "self.navigationitem". Whenever I present modalviewcontroller with the navigationcontroller, this navigation comes below the actual navigationcontroller.

Can anybody please help?

Thanx in advance.

A: 

Whenever I present modalviewcontroller with the navigationcontroller, this navigation comes below the actual navigationcontroller.

That problem is because calling presentModalViewController: on self, you should call it on self.navigationController that way the navigation controller won't be shown below the other one.

As to why you can't set the navigationController's properties, I don't know. It looks Ok to me. But I expect it is because you are setting the properties before viewDidLoad is called by the nib-loader. I think I remember having problems like this myself a long time ago.

You should set the title etc. in the UIViewController subclass's viewDidLoad method and I think you worries will be over.

Thomas Børlum
A: 

I've created a simple view based app with xcode template, then i've added your code and it's working for me...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.

// Add the view controller's view to the window and display.

TestViewController *fullListTopCompaniesInstance = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];

UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];

[fullListTopCompaniesInstance setTitle:@"TEST"];


UIBarButtonItem *submit = [[UIBarButtonItem alloc]
                           initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                           target:self
                           action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;

[window addSubview:viewController.view];
[window makeKeyAndVisible];

[viewController presentModalViewController:cntrol animated:YES];

[cntrol release];
[submit release];

return YES;

}

Chiodo