调用initWithNibName不会初始化nib中的项,它有0x0 [英] calling initWithNibName doesn't initialize items in the nib, it has 0x0

查看:105
本文介绍了调用initWithNibName不会初始化nib中的项,它有0x0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打电话时:

self.viewController = [[DidItViewController alloc] initWithNibName:@"DidItViewController" bundle:nil];

然后我在调试器中执行此行后立即检查self.viewController.navController,我发现它是空的(0x0)。

and then I check self.viewController.navController right after this line is executed in the debugger, I find that it's empty (0x0).

在DidItViewController上我把我的navController定义为:

On DidItViewController I have my navController defined as:

IBOutlet NavigationController *navController; 

在我的nib文件中,我将NavigationController绑定到文件所有者的这个navController属性(一个DidItViewController) )。

and in my nib file I have the NavigationController bound to this navController property on the File Owner (a DidItViewController).

为什么我的navController没有被创建?有任何想法吗?我想我可能会错过关于initWithNibName工作方式的一些内容。

Why doesn't my navController get created? Any ideas? I think I may be missing something about the way initWithNibName works..

谢谢。

推荐答案

或者您可以使用 [NSBundle loadNibNamed:owner:options:] 方法代替。此方法可确保连接所有插座连接。 ( [UIViewController initWithNibName:bundle:] 没有)

Or you can use [NSBundle loadNibNamed:owner:options:] method instead of. This method ensures all outlet connections connected. (which [UIViewController initWithNibName: bundle:] doesn't)

在这种情况下,NIB中的文件所有者是PhotoShow类的外部实例。

In this case, File's Owner in the NIB is an external instance of PhotoShow class.

// This works completely. All outlets works.
PhotoShow* obj = [[PhotoShow alloc] init];
[[NSBundle mainBundle] loadNibNamed:@"PhotoShow" owner:obj options:nil];
// Outlets are always available at this moment.

// This works. but does not connects outlets correctly sometimes.
PhooShow* obj = [[PhotoShow alloc] initWithNibName:@"PhotoShow" bundle:[NSBundle mainBundle]];
// Outlets may not available at this moment.



从参考文件中选择



你可以使用此方法加载用户界面并使对象可用于您的代码。在加载过程中,此方法取消归档每个对象,初始化它,将其属性设置为其配置值并重新建立与其他对象的任何连接。 (要建立插座连接,此方法使用setValue:forKey:方法,这可能会导致插座中的对象自动保留。)有关nib加载过程的详细信息,请参阅资源编程指南。

Selection from reference document

You can use this method to load user interfaces and make the objects available to your code. During the loading process, this method unarchives each object, initializes it, sets its properties to their configured values, and reestablishes any connections to other objects. (To establish outlet connections, this method uses the setValue:forKey: method, which may cause the object in the outlet to be retained automatically.) For detailed information about the nib-loading process, see Resource Programming Guide.

这篇关于调用initWithNibName不会初始化nib中的项,它有0x0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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