Quote:
Originally Posted by emansfield
Hi,
I have a UIViewController object which is being presented as a modal view, but I am unable to set the view title. I want the title to vary depending on the context. I have tried the following:
- (void) viewWillAppear  BOOL)animated {
self.title = (category ? category.name : @"Add New Category");
}
I have also tried:
- (void) viewWillAppear  BOOL)animated {
self.navigationController.title = (category ? category.name : @"Add New Category");
}
neither of the above display any title.
If I set a constant title in the NIB file entry for the view controller in Interface Builder then it displays the title, but I need to be able to set it programmatically.
I can set the title for a view using the first example above on a view controller that is pushed onto the navigation controller's stack and that displays correctly, but it won't do it when presenting the view as a modal view.
Can anyone tell me what I need to do, please.
|
---
The discussion on this thread shows me there are other, simpler
approaches to the problem of setTitle for a NavBar. Still I send on
these thoughts.
I was unable to dynamically change the title of a ModalView.
It would take a bit of work to rework the NIBs, and switch to pushing a Modeless one.
(Plus I believe you should/can not push a modeless one from a modal one)
I made a copy of the NIB file for the ModalView I had, AddPhotoView.XIB
and changed only the Title in the navigationItem, giving two
versions of a view (AddPhotoView.XIB and EditPhotoView.XIB),
both of which using the same controller Class.
This allowed me to dynamically decide which Title to display
, using virtually identical NIBs.
There are to instance variables for the same Class:
AddPhotoViewController* addPhotoViewController; // Title: ADD PHOTO
AddPhotoViewController* editPhotoViewController; // Title: EDIT PHOTO
This seems "heavy handed" to me, but works.
- (AddPhotoViewController *)addPhotoViewController{
// only Title varies between ePVC and aPVC
if(addPhotoViewController == nil){
addPhotoViewController = [[AddPhotoViewController alloc] initWithNibName:@"AddPhotoView" bundle:nil];
}
return addPhotoViewController;
}
- (AddPhotoViewController *)editPhotoViewController{
// only Title varies between ePVC and aPVC
if(editPhotoViewController == nil){
editPhotoViewController = [[AddPhotoViewController alloc] initWithNibName:@"EditPhotoView" bundle:nil];
}
return editPhotoViewController;
}