简体   繁体   English

在加载视图时获取NULL IBOutlets有什么可能性.. IOS

[英]What are the possibilities of getting NULL IBOutlets while loading a view.. IOS

I have been working on IOS application. 我一直在研究IOS应用程序。 Before I had single project in which all source code was there application loaded properly in that setup, now I had split that into multiple projects. 在我有单个项目之前,所有源代码都是在该设置中正确加载了应用程序,现在我将其拆分为多个项目。 After that I am facing now a problem... in ViewDidLoad, IBOutlet for buttons all are coming nil values, view also loading black colored. 之后我现在面临一个问题...在ViewDidLoad中,IBOutlet的按钮都是零值,视图也加载黑色。 I am not able to guess what was the problem. 我无法猜出是什么问题。 Any idea about what could cause this... 任何可能导致这种情况的想法......

I have loaded my view like this... 我加载了我的观点......

 main =[[main_page_controller alloc] init];

    if (main != NULL) 
        [root.navigationController pushViewController:main animated:YES];

I am not sure which part of the code do I need to post here, to make the question more understandable... Please share your suggestions.. 我不确定我需要在这里发布哪部分代码,以使问题更容易理解......请分享您的建议..

Edit: I ran my old project and then tried with my new set up application launching successfully. 编辑:我运行了我的旧项目,然后尝试使用我的新设置应用程序成功启动。 I removed the application from device, and loaded using new set up only, problem again shows up. 我从设备中删除了应用程序,并仅使用新设置加载,问题再次显示出来。 So what was there in old set up? 那么旧的设置是什么? What am I missing in new... ???? 我在新的...中错过了什么?

First check all your connection in xib(nib) file, if its already connected then just disconnect them , clean project (cmd+k) and then connect connection again. 首先检查xib(nib)文件中的所有连接,如果已连接,则断开它们,清理项目(cmd + k) ,然后再次连接连接。

take a look on this image for connection 看看这张图片是否有联系

在此输入图像描述

Refer to the documentation 请参阅文档

To initialize your view controller object using a nib, you use the initWithNibName:bundle: method to specify the nib file used by the view controller. 要使用nib初始化视图控制器对象,可以使用initWithNibName:bundle:方法指定视图控制器使用的nib文件。 Then, when the view controller needs to load its views, it automatically creates and configures the views using the information stored in the nib file. 然后,当视图控制器需要加载其视图时,它会使用存储在nib文件中的信息自动创建和配置视图。

When initialising a view controller, and you're using a .xib file for the view, you need to call initWithNibName:bundle: . 初始化视图控制器,并且您正在为视图使用.xib文件时,需要调用initWithNibName:bundle: . This means it'll use the xib file to create the view within loadView . 这意味着它将使用xib文件在loadView创建视图。 At the moment, you're just using init , that will create a blank UIViewController object. 目前,您只是使用init ,这将创建一个空白的UIViewController对象。

So in this case, your code would be (assuming the .xib is called "MainViewControllerView.xib" within the main bundle): 所以在这种情况下,你的代码就是(假设主包中的.xib被称为“MainViewControllerView.xib”):

main =[[main_page_controller alloc] initWithNibName:@"MainViewControllerView" bundle:nil];
if (main) {
    [root.navigationController pushViewController:main animated:YES];
}

Also sanity check your .xib file to see if all the IBOutlet s are connected to what you want. 还要检查你的.xib文件,看看是否所有的IBOutlet都连接到了你想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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