PrEV
Thoughts from a NeXTStep Guy on Cocoa Development

Presenting Modal Views Bug

Apr 25, 2009 by Bill Dudney

While continuing on the retooling of the iPhone book I ran into an irritating bug that has a very simple work around.

When you present a modal view controller via the presentModalViewController:animated: method the viewWillAppear: method gets called on the modal view controller before the view is actually loaded. This is a pain in the neck for me because I set the values for my GUI bits in this method. It was very irritating to see all my outlets being nil when they clearly should have been set to the connections I made in IB.

I found the bug by breaking in a much later method (one of the actions my modal VC implemented) and of course everything was set up as it should be (otherwise the action would not have been invoked). That led me to implement viewDidLoad and that is where I found that viewDidLoad was being called after viewWillAppear:

Fortunately this bug has a really simple work around. Before you present your view controller make it load its view by calling the view method. Here is some sample code.

- (IBAction)modal {
  [self.second view];
  [self presentModalViewController:self.second animated:YES];
}

Hope this helps someone avoid the hour or so it took me to track this down. I would expect this to be fixed in a upcoming release so this is not a long term need, but for your 2.2 apps it will hopefully help.

Permalink     7 Comments - Add Yours

Life...

Apr 03, 2009 by Bill Dudney

I have been so busy lately, its all been good but man what a crazy 3 or 4 weeks.

Right now I'm in the UK (some pics) getting ready for the NSConference put on by the great folks over at Mac Developer Network. I can't wait for the conference, its going to be a blast. But since I was coming all the way to the UK we figured that we should bring the whole family and make a trip of it. So everyone is here, we got cheap tickets by coming over on March 31 (2 weeks before the conference started). So now I'm running around doing all sorts of fun tourist stuff, nearly dying because of driving on the 'wrong' side of the road etc. We are finally starting to adjust to the time zone, but its gradual kids don't much get going to bed at what to their body is 1PM... It has been great fun so far though!

The week before this trip started I was at the Philly Emerging Technologies conference giving an 'Intro to iPhone Dev' talk. It was a blast and I meet some really smart folks there. Chariot and the other sponsors put on quite a show.

The week before that I was in Reston VA teaching the iPhone Studio. This was the first public class on the East Coast of the US and we had a great time. It was my first time back there in quite a while so it was great to catch up with some old friends.

The there was also the iPhone 3.0 beta, which is very exciting indeed but has caused me to go back over all my stuff for the iPhone Book. I am just about done with the 2.x tech review comments so I'll be starting in earnest on 3.0 work early next week.

Crazy but extremely fun times, if I am a bit quite here now you know why. In the mean time you can follow me on twitter.

Permalink     2 Comments - Add Yours