Objective c 添加子视图未显示我的uiview

Objective c 添加子视图未显示我的uiview,objective-c,addsubview,Objective C,Addsubview,我有下面的代码,并且uiview没有显示,我已经放置了一个断点&查看视图不是nil并且帧被设置为给定的大小-为什么视图没有显示在我的uiviewcontroller中 @property (nonatomic,strong) LoadingView *loadingView; self.loadingView = [[[NSBundle mainBundle] loadNibNamed:@"LoadingView" owner:self options:nil] objectAtIndex:0

我有下面的代码,并且uiview没有显示,我已经放置了一个断点&查看视图不是nil并且帧被设置为给定的大小-为什么视图没有显示在我的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];

您的代码在逻辑上是错误的。在将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;
}
nib分配应该在
LoadingView
类的initwithframe方法中。 然后,添加视图的实现如下所示:

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

在哪里添加视图?你确定self.view已经加载了吗?@tadasz在我的一个方法中