简体   繁体   English

initWithNibName不起作用

[英]initWithNibName not working

Just ran into this very frustrating problem when trying to add a new view, I have 2 different types of view: LargeCoverViewController and CoverViewController . 尝试添加新视图时遇到了一个非常令人沮丧的问题,我有两种不同类型的视图: LargeCoverViewControllerCoverViewController

I created a LargeCoverViewController like this: 我创建了一个LargeCoverViewController如下所示:

LargeCoverViewController *tmpCover = [[LargeCoverViewController alloc] initWithNibName:@"LargeCoverViewController" bundle:nil andIssue:issue];

That just works, but when I try to create a CoverViewController , it refuses to work 那是CoverViewController ,但是当我尝试创建CoverViewController ,它拒绝工作

CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:@"CoverViewController" bundle:nil andIssue:issue];

I'm thinking it has something to do with the .xib file, when I do like this it "works" again 我在想它与.xib文件有关,当我这样做时,它又可以“工作”了

CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:@"LargeCoverViewController" bundle:nil andIssue:issue];

In Interface Builder the class is set properly, my view is linked up correctly. 在Interface Builder中,该类设置正确,我的视图已正确链接。 (It's basically just a copy of the LargeCoverViewController), am I still missing something? (它基本上只是LargeCoverViewController的副本),我还缺少什么吗? It's getting very frustrating ... 越来越令人沮丧...

EDIT: My application doesn't crash, if my nibname was wrong the application should crash, which isn't the case here. 编辑:我的应用程序不会崩溃,如果我的nibname错误,应用程序应该崩溃,这不是这里的情况。

Try creating new separate XIB file rather copying whole XIB file and then copy the UI outlets and views from other XIB to this newly created XIB file. 尝试创建新的单独的XIB文件,而不是复制整个XIB文件,然后将UI插座和视图从其他XIB复制到此新创建的XIB文件。

Sometimes, Xcode gets confused with copy-pasting. 有时,Xcode与复制粘贴相混淆。 I know this is not proper solution but sometimes it works. 我知道这不是适当的解决方案,但有时可以。 :) :)

复制ViewController时,文件所有者的自定义类保持不变,因此将其更改为新的ViewController,并在更改后再次绑定视图。

Is your application getting crashed on that line? 您的应用程序在那行崩溃了吗? Check the console for the logs. 检查控制台中的日志。 You may have got error messages or crash logs. 您可能收到错误消息或崩溃日志。

If you copied XIB resources from any other XIB then check for the linked outlets with objects which may not be available to this new class. 如果您从任何其他XIB复制了XIB资源,请检查链接的插座是否包含该新类可能不可用的对象。

I hope this will help you and will able to resolve the issue. 希望对您有所帮助,并且能够解决该问题。

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

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