2

I have a navigation controller and in it a view controller:

-NavigationController1
--MyViewController

And as well I have another navigation controller - NavigationController2. I want to call MyViewController from another view controller - ViewController2, that was pushed into NavigationController2. -NavigationController2 --ViewController2

I do it in the following way:

@implementation ModifyDicVController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.navigationItem.rightBarButtonItem = [ [ [UIBarButtonItem alloc]
                    initWithBarButtonSystemItem:
                    UIBarButtonSystemItemAdd target:self
                    action:@selector(add_clicked)] autorelease];

}


-(void) add_clicked
{
    [navigationController pushViewController: addWordsVController animated: YES];
}

@end

And here is the viewWillAppear method of MyViewController(the one that is being called):

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setTitle: @"My title"];
}

I am adding a "done" button to the Navigation Bar when user starts to edit a text field:

- (void) textFieldDidBeginEditing: (UITextField *) textField
{ 
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
                initWithTitle: NSLocalizedString(@"button: done", @"")
                style:UIBarButtonItemStyleDone 
                target:self 
                action:@selector(doneEditing)] 
                autorelease];
}

The problem is: if I call MyViewController from ViewController2 that was pushed into NavigationController2 and after that I call MyViewController from its own NavigationController1, the title of a navigation bar and a done button is not being added. However viewWillAppear and textFieldDidBeginEditing methods of MyViewController are being called.

What is the problem and how can I fix it?

Thanks.

2
  • Can you explain the hierarchy of nav controllers in more detail? Jun 5, 2009 at 20:03
  • It is an application similar to address book. I have a tab bar from which I can choose an address book to edit(I have several books) and as well I can choose a tab from where I can add a new contact to an active address book. Both tabs are navigation controllers. And it is possible as well to add a new contact to an address book by going into the first tab, select a particular address book to edit and from there add new contacts. Jun 5, 2009 at 20:49

2 Answers 2

1

Your question is a little confusing.

I "think" you are saying you are having issues communicating between view controllers.

If this is the case, the real issue is that your view controllers should NOT be communicating with each other. They, instead should be storing state in a model.

If you do this, then you will have no issues. Consider having a model singleton to save the information that is getting lost.

If I have misunderstood your issue, please let me know.

0

To change the title use in the view controller that is currently on top of the stack (active).

self.navigationItem.title=@"the title";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.