-1

I have the following code, and the uiview is not showing, i've placed a breakpoint & see the view is not nil and the frame is set to the given size - why the view is not showing in my 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];
liv a
  • 3,232
  • 6
  • 35
  • 76

1 Answers1

0

Your code is logically wrong. Your LoadingView class must allocate before you assigning nib member to it.

- (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;
}

Your nib assignment should be in the initwithframe method of LoadingView class. Then Your implementation of adding view would be like,

self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(110,170,100,100)];
[self.view addSubview:self.loadingView];
Tirth
  • 7,801
  • 9
  • 55
  • 88