IBOutlet未在awakeFromNib中连接 [英] IBOutlet isn't connected in awakeFromNib

查看:264
本文介绍了IBOutlet未在awakeFromNib中连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处链接的示例代码效果很好,允许UIScrollView显示带有分页的图像,并预览当前图像之前和之后的图像:

The sample code linked here works great and allows a UIScrollView to display images with paging and preview of the images before and after the current image:

  • http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html
  • https://github.com/alexrepty/Paging-Enabled-UIScrollView-With-Previews

我是尝试将示例封装在可以重用的单个控件中。所以我创建了一个PagingScrollView:

I'm trying to encapsulate the example in a single control that can be reused. So I created a PagingScrollView:

@interface PagingScrollView : UIView {
    IBOutlet UIScrollView * scrollView;
}

@property (nonatomic,retain) IBOutlet UIScrollView * scrollView;

@end

污垢简单实施

- (void) awakeFromNib
{
    [super awakeFromNib];

    NSLog(@"awake from nib");
}

在PagingScrollView.xib中,我放置了一个包含UIScrollView和ARScrollViewEnhancer的View与在原始ScrollViewPagingExampleViewController xib中一样。它的File's Owner的类设置为PagingScrollView,其scrollView插座设置为子UIScrollView。

In PagingScrollView.xib, I put a View containing a UIScrollView and a ARScrollViewEnhancer exactly as in the original ScrollViewPagingExampleViewController xib. Its File's Owner's class is set to PagingScrollView, and its scrollView outlet is set to the child UIScrollView.

在ScrollViewPagingExampleViewController中,我只是声明:

In ScrollViewPagingExampleViewController, I simply declare:

IBOutlet PagingScrollView   *pagingScrollView;

在IB中,我拖动一个View,将其类设置为PagingScrollView,并挂起其pagingScrollView插座到pagingScrollView。

And in IB, I drag a View, set its class to PagingScrollView, and hook up its pagingScrollView outlet to the PagingScrollView.

在awakeFromNib中,scrollView属性为nil。我认为既然scrollView在同一个nib中连接在IB中,那么它就可以使用了。

In awakeFromNib, the scrollView property is nil. I would think that since the scrollView is hooked up in IB in the same nib, it would be available by this point.

令人困惑的是,在ScrollViewPagingExampleViewController.xib中,有一个空出口名为scrollView。这可能表明PagingScrollView的实例与PagingScrollView.xib中定义的实例不同。

Confusingly, in ScrollViewPagingExampleViewController.xib, there is an empty outlet named scrollView. This might indicate that there is a different instance of PagingScrollView than the one defined in PagingScrollView.xib.

因此,我无法使用实际的子项填充UIScrollView观点。我在这里做错了什么?

As a result, I can't populate the UIScrollView with the actual child views. What am I doing wrong here?

推荐答案

这里有一个非常好的答案:在awakeFromNib中查看视图?

There is a very good answer to this question here: Accessing View in awakeFromNib?

长话短说,视图可能在awakeFromNib中加载,但其内容是懒惰加载的,这就是为什么你应该使用viewDidLoad而不是awakeFromNib来实现你想要实现的目的。

Long story short, the view may be loaded in awakeFromNib, but its contents are loaded lazily, which is why you should use viewDidLoad instead of awakeFromNib for what you are trying to achieve.

这篇关于IBOutlet未在awakeFromNib中连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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