I have a UIView, that contains 3 other subviews. At the beginning, I do not add these 3 subviews into the UIView, instead I created them separately as follow:
I want to add the subview dynamically. So I try this code as follow:
Add MainView to UIViewController
UINib *nib = [UINib nibWithNibName:@"MainView" bundle:nil]; MainView* mainView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]; [self.view addSubview:mainView];
It's ok so far. But now, in the MainView class, I add the subView, I got crash
UINib *nib = [UINib nibWithNibName:@"SubView1" bundle:nil]; SubView1* subView1 = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]; [self addSubview:subView1];
What's wrong with my code?