2014-01-16 33 views
-1

我有以下代码,并没有显示uiview,我已经放置了一个断点&看到视图不是零和框架设置为给定大小 - 为什么视图是没有显示在我的uiviewcontroller?添加子视图不显示我的用户界面

@property (nonatomic,strong) LoadingView *loadingView; 

self.loadingView = [[[NSBundle mainBundle] loadNibNamed:@"LoadingView" owner:self options:nil] objectAtIndex:0]; 
self.loadingView.frame = CGRectMake(110,170,100,100); 

[self.view addSubview:self.loadingView]; 
+0

你在哪里添加视图?你确定self.view已经被加载了吗? – tadasz

+0

@tadasz在我的方法之一 –

回答

0

您的代码在逻辑上是错误的。在将nib成员分配给它之前,您的LoadingView类必须进行分配。

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
     NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"LoadingView" owner:self options:nil]; 
     self = [nibs objectAtIndex:0]; 
    } 
    return self; 
} 

您的笔尖分配应该在LoadingView类的initwithframe方法中。 然后你的添加视图的实现将会像,

self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(110,170,100,100)]; 
[self.view addSubview:self.loadingView]; 
相关问题