Objective-C nil Outlets

霸气de小男生 提交于 2019-12-11 04:58:15

问题


I have a class used for a user interface, with two constructors:

- (id)initWithBanner:(NSMutableArray *)banner {  
    if ( ( self = [super initWithNibName:@"UIBanner" bundle:nil] ) ) {
      // ... code...
    }
    return self;
}

- (id)initWithPreview:(NSMutableArray *)previews {
    if ( ( self = [super initWithNibName:@"UIBanner" bundle:nil] ) ) {
      // ... code...
    }
    return self;
}

Inside this two constructors, I use two outlets, a UIPageControl and a UIScrollView, linked with the new XCode 4. Now, if I use the first constructor, initWithBanner, everything works fine (putting a NSLog(@"%@",bannerScroll) gives the relative outlet description) but when I use initWithPreview, my Outlets are nil. What's wrong with that?


回答1:


Your outlets will not be set until the nib is actually loaded, which occurs when your UIViewController's view property is read. You implement the -viewDidLoad method to handle when your nib has loaded. Also note that the view and nib can be unloaded and loaded multiple times during the life of your UIViewContoller instance.



来源:https://stackoverflow.com/questions/5309759/objective-c-nil-outlets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!