Objective-C nil Outlets [英] Objective-C nil Outlets

查看:65
本文介绍了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;
}

在这两个构造函数中,我使用了两个出口,一个 UIPageControl 和一个 UIScrollView,与新的 XCode 4 链接.现在,如果我使用第一个构造函数 initWithBanner,一切正常(放置一个 NSLog(@"%@",bannerScroll) 给出了相关的出口描述)但是当我使用 initWithPreview 时,我的出口为零.这有什么问题?

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?

推荐答案

在实际加载笔尖之前不会设置您的插座,这发生在您的 UIViewController 的 view 属性被读取时.你实现 -viewDidLoad 方法来处理你的笔尖加载.另请注意,在 UIViewContoller 实例的生命周期中,视图和笔尖可以多次卸载和加载.

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.

这篇关于Objective-C nil Outlets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆