iPhone – Load UiView from NIB as another subview of UIView from NIB loading

The idea is basically:
Inside the myViewController NIB, I have a UIView as a subview, connected to the IBOutlet on the MyViewController class. I want to load the UIView subview from the NIB. subView also has a class associated with it. But the subview is not displayed. This is my job

On MyViewController.h

 @interface MyViewController: UIViewController {
IBOutlet SubView *subView; // this outlet is connected to an empty UIView on IB
}
@end

On MyViewController.m

-(id)init {
if ((self = [super init])) {
// load the main view
[[NSBundle mainBundle] loadNibNamed:@"myViewController" owner:self options:nil];
// load the sub view from another NIB
self.subView = [[[NSBundle mainBundle] loadNibNamed:@" subView" owner:self options:nil] objectAtIndex:0];
}
}

SubView.h is defined as:

@interface SubView: UIView {
}
@end

What am I doing wrong?

GianPac – shameless self-promotion, but I did a blog post about this a month ago . Feel free to ignore the code related to shadows.

http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/< /p>

Also, I (thanks to several people for the advice) avoid having multiple view controllers on my’view’. The method outlined above allows you to accomplish this and still use IB to perform the layout/outlet.

The idea is basically:
Inside the myViewController NIB, I have a UIView as a subview, connected to the IBOutlet on the MyViewController class. I want to load from the NIB UIView subview. subView also has a class associated with it. But the subview is not displayed. This is my job

On MyViewController.h

@interface MyViewController: UIViewController {
IBOutlet SubView *subView; // this outlet is connected to an empty UIView on IB
}
@end

In MyViewController.m on

-(id)init {
if ((self = [super init])) {
// load the main view
[[NSBundle mainBundle] loadNibNamed:@"myViewController" owner:self options:nil];
// load the sub view from another NIB
self.subView = [[[NSBundle mainBundle] loadNibName d:@"subView" owner:self options:nil] objectAtIndex:0];
}
}

SubView.h is defined as:

@interface SubView: UIView {
}
@end

What am I doing wrong?

GianPac – shameless self-promotion, but I did a blog post about this a month ago. Feel free to ignore the code related to the shade.

http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/

In addition, I (thanks to Personal suggestion) Avoid having multiple view controllers on my’view’. The method outlined above allows you to accomplish this and still use IB to perform the layout/outlet.

< /p>

Leave a Comment

Your email address will not be published.