开发者

Add subview not working?

I have two xib files:

MainView.xib and DetailView.xib

Both are controlled by MainViewController. MainView.xib loads when the app first opens, but if a user clicks on a button, the app loads DetailView.xib as a subview.

DetailView should load because I made an IBOutlet in the MainViewController to the view in the DetailView.xib file.

I am trying to use the addSubview command, but for some reason it is not actually executing the command. It will go through the command, but nothing will actually change. Here is the command:

[self.view addSubview:myDetailView]

where myDetailView is the IBOutlet

Wh开发者_JS百科at is wrong with this setup?

Thanks for the help.

EDIT:

MainViewController.h (left generated code out):

IBOutlet UIView *myDetailView;

@property (nonatomic, retain) IBOutlet UIView *myDetailView;

MainViewController.m:

@synthesize myDetailView;


NSLog myDetailView before you add the subview, and if it returns "(null)" then the myDetailView has not been initialised. Make sure that you have connected the view in Interface Builder.


I bet myDetailView is nil. It may be an IBOutlet, but it has to be connected. And the XIB in which you connected the IBOutlet should obviously be loaded.

How did you load the DetailView.xib in your code? Did you use loadNibNamed:owner:options:?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜