简体   繁体   中英

Objective-C nil Outlets

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM