The keys to the Kingdom

The biggest problem that I have had over the past 2 years or so of working with the iPhone SDK is the seemingly insurmountable learning curve to have you applications do something reasonably simple. I think this is partly due to my lack of any free time to dive into the whole iPhone SDK/Cocoa Touch/Objective-C world, and partly due to my straight ahead, VB6 development mentality.

For example, in my VB6 applications, if I need to display a dialog to the user to collect some bit of information, the parent code creates the form and shows it, and the child code closes down the child form when the user is done. This reasonably simple task has proven a bit elusive, as it seems like at times, I can’t get this to work for one reason or another.

Alas, I think I have finally figured out a good way to do this very task. Now, all I do in my parent view controller is to run the following code when I need to:

ChildViewController *controller = [[ChildViewController alloc]
					initWithNibName:@"ChildViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];

In the new view that comes up by calling the code above, I use this code to get rid of the new view:

[[self parentViewController] dismissModalViewControllerAnimated:YES];

(Now of course, there is more going on here, as you need a way to pass values back and forth from one view to another. I think I might have a blog post from a few months ago to talk about this process.)

The end result is that I now have a simple way to show and dismiss forms in much the same way that I did with VB6. Does discovering this mean that I will continue to bumble around in the dark when it comes to the mysteries of inheriting from the correct classes in the iPhone SDK? Probably. Am I worried about it? Nope.

Oh, and I hope everyone has a nice Christmas (or insert your own holiday here, Kwanzaa, Festivus, Hanukkah, etc.), and drive safely out there. Grandma still hasn’t recovered after being run over by a reindeer.

Leave a Reply