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.