0

This is the code that executes when a button is tapped in the view for the viewcontroller that displays the modal dialog:

-(IBAction)presentModally:(id)sender {  

if (self.nvc == nil) {
MyModalViewController *vc = [[MyModalViewController alloc] init];
UINavigationController *navvc = [[UINavigationController alloc] initWithRootViewController:vc];
navvc.navigationItem.prompt = @"";
navvc.navigationBar.barStyle = UIBarStyleBlack;
[vc release];
self.nvc = navvc;
[navvc release];
}
}

[self presentModalViewController:self.nvc animated:YES];

This code should if everything was correct launch every time the view appear.

- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"test");
}

When I comment the if-statement that checks if the Ivar is nil the method viewWillAppear is invoked. Any ideas?

LuckyLuke
  • 42,935
  • 77
  • 254
  • 416
  • do you hace a closing bracket for the `if`? As written, there's only one closing bracket. Also, put up the code with `viewWillAppear` too. Are they next to eachother in the file? – Stephen Furlani Jan 12 '11 at 21:52

1 Answers1

3

Andreas,

not sure if you are confusing viewDidLoad and viewWillAppear here? Your viewDidLoad code will not get called every time the view appears, only on load.

Also, displaying a Navigation controller as a modal view seems a strange thing to do to me - the whole point of modal views is they prevent the user navigating away as you get them to complete some task, like sending an email link, then they dismiss it and go back to where they were.

Brynjar
  • 1,162
  • 8
  • 22
  • The UINavigationController is used because I have a toolbar at the bottom. I want to use the stack that the navigationcontroller to acheive this. – LuckyLuke Jan 12 '11 at 22:22
  • So you want a toolbar at the bottom of your modal view? – Brynjar Jan 12 '11 at 22:32
  • Yes, but I understand what you are saying. I have now redesigned it and it works. Thank you. – LuckyLuke Jan 12 '11 at 23:06
  • @Brynjar I think modal presentation and navigation controllers are not mutually exclusive. If the task you wish the user to perform is complex enough to warrant more than one screenful and the task should preclude other interactions, this is appropriate. A good example is in the contacts app when adding a photo (the modal task allows you to select the album, then the photo, and is presented in a nav controller). – jinglesthula Jul 06 '11 at 01:01
  • @jinglesthula - on looking at this again, yes I agree with you. – Brynjar Jul 06 '11 at 09:53