Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically declare child UiViewController in main UiViewController
    primarykey
    data
    text
    <p>In my program, I have to declare and use the multiple child <code>UIViewController</code> like a custom control in my main <code>UIViewController</code>. But when I click on the button of one of the child UIView Controllers I get a <code>EXC_BAD_ACCESS</code> error. Please see the following my sample code structure.</p> <p>Example 1:</p> <pre><code>//--Child------------------------------------------------------------------- @interface subUIViewController&lt;UIViewController&gt; -(IBAction)myButtonClick:(id)Sender; -@implementation subUiViewController -(IBAction)myButtonClick:(id)Sender { NSLog(@"Button Click Event....."); } //---Main-------------------------------------------------------------------- @interface mainUIViewController&lt;UIViewController&gt; @implementation mainUIViewController -(void)viewDidLoad { [super viewDidLoad]; subUiViewController *subViewController=[[subUiViewController alloc] initWithNibNameAndArtist:@"subUiViewController" bundle:nil]; [self.view addSubView: subViewController.view]; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- </code></pre> <p>But if I declare with <code>@property (retain,nonatomic) subUiViewController *subViewController</code> in <code>MainViewController</code>, it is working without error. Please see the following code.</p> <p>Example 2:</p> <pre><code>//---Child------------------------------------------------------------------ @interface subUIViewController&lt;UIViewController&gt; -(IBAction)myButtonClick:(id)Sender; @implementation subUiViewController -(IBAction)myButtonClick:(id)Sender { NSLog(@"Button Click Event....."); } //----Main----------------------------------------------------------------- @interface mainUIViewController&lt;UIViewController&gt; @property(retain,nonatomic) subUiViewController *subViewController; @implementation mainUIViewController @synthesize subViewController; -(void)viewDidLoad { [super viewDidLoad]; subViewController=[[subUiViewController alloc] initWithNibNameAndArtist:@"subUiViewController" bundle:nil]; [self.view addSubView: subViewController.view]; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload