开发者

Setting Navigation Item Title in a modal view

开发者 https://www.devze.com 2023-03-13 21:37 出处:网络
In reviewing the existing answers, I think Steve\'s question and codelark\'s answer comes the closet to my issue. But I am missing something here.

In reviewing the existing answers, I think Steve's question and codelark's answer comes the closet to my issue. But I am missing something here.

My xib for the modal view: IFDNewFormViewController.xib:

View Controller
> Table View
>> View
>>> Navigation Bar
>>>> Navigation Item - New Form
>> View
>>> Toolbar
>>>> Bar Button Item - Cancel
>>>> Bar Button Item - Flexible Space
>>>> Bar Button Item - Done

My method that gets called at a button press:

IFDNewFormViewController.m:

- (void) newFormDisplay:(id)sender {
    // Show the Create Flightlog View
    IFDNewFormViewController *newForm = [[IFDNewFormViewController alloc] init];
    newForm.flightlogDelegate = self;
    newForm.dataType = [self ifdDataType];
    newForm.displayDataType = [NSString stringWithFormat:@"New %@",[self displayDataType]];
    newForm.title = [NSString stringWithFormat:@"Title %@",[self displayDataType]];
    newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
    newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
    newForm.modalViewController.title = [NSString stringWithFormat开发者_如何学Python:@"ModalViewController.Title %@",[self displayDataType]];


    NSLog(@"iFDListViewController_Pad:newFormDisplay start form for dataType=%@ (%@)",[self ifdDataType], [self displayDataType]);
    [self presentModalViewController:newForm animated:YES];
    [newForm release];
}

I have set the title in xib:

Navigation Item - New Form -> title.

That title is the one on displayed on the view. Using the information found in this forum I added the following lines:

newForm.navigationItem.title = [NSString stringWithFormat:@"NavItem.Title %@",[self displayDataType]];
newForm.navigationController.title = [NSString stringWithFormat:@"NavController.Title %@",[self displayDataType]];
newForm.modalViewController.title = [NSString stringWithFormat:@"ModalViewController.Title %@",[self displayDataType]];

Still no joy.

I am missing something here. Any ideas?


Since you are not pushing this view controller onto a UINavigationController, setting newForm.navigationItem.title won't do the trick.

It looks like you are pushing a modal view controller that contains it's own navigation bar. In that case, you'll probably need to create your own reference to it and tie the bar in the xib to it.

In IFDNewFormViewController.h create an instance variable

    UINavigationBar *customNavBar;

and an outlet property

    @property (nonatomic, retain) IBOutlet *UINavigationBar customNavBar;

In IFDNewFormViewController.m:

    @synthesize customNavBar;

Be sure to release it in dealloc and set to nil in viewDidUnload.

When editing the xib, right click on your navigation bar then click and drag the open circle next to "New Referencing Outlet" up to the file's owner and select customNavBar. That way the property will contain the bar from your xib after it is loaded.

When you init your IFDNewFormViewController, be sure to use the following:

    IFDNewFormViewController *newForm = [[IFDNewFormViewController] alloc] initWithNibName:@"whatever-the-file-name-is" bundle:nil];

Or the data in the xib won't even be used.

0

精彩评论

暂无评论...
验证码 换一张
取 消