In my program, I have to declare and use the multiple child UIViewController like a custom control in my main UIViewController. But when I click on the button of one of the child UIView Controllers I get a EXC_BAD_ACCESS error. Please see the following my sample code structure.

I don't know why Example 1 is not working and Example 2 is working. For me, I need to use example 1 because I need to programatically create a child ui view controller based on Core Data Return. Could you please help me to point out what is wrong ? How can I dynamically declare child ui view controller in code?

3 Answers
3

ceases to exist after viewDidLoad finishes. Normally in an iPhone app each screen is it's own view controller. And if you want to load a new screen/viewController you would create it like you did and either display it Modally or if you are using a navigationController push it on the stack.

But if you want to do what you are doing your main viewController would need a property of type id that could hold whatever type of viewController you create.

Depending on what you are doing the new ability in iOS 5 for a View Controller to be a container view controller for other view controllers might be useful. Specifically the method

Just as EricLarSOn explained. However, in your situation, what you can do it to declare generic var with property and instaintiate whatever the childviewcontroller class dynamically and assigned it to the generic var as mentioned earlier.
For example replace your