简体   繁体   English

选项卡式应用程序中用于视图控制器的其他NIB

[英]additional NIB for view controller in tabbed app

{Xcode 4.2, deployment target iOS4.3, not storyboard, using ARC} {使用ARC,Xcode 4.2,部署目标是iOS4.3,而不是故事板}

I started with a tabbed application template & chose the universal platform, which nicely gives me view controller classes & NIB files for an iPhone ( ClassName_iPhone.xib ) & an iPad ( ClassName_iPad.xib ) for 2 tabs, with an if statement in the AppDelegate to determine which to run - exactly how I wanted it set up. 我从选项卡式应用程序模板开始,选择了通用平台,该平台很好地为我提供了两个选项卡的iPhone( ClassName_iPhone.xib )和iPad( ClassName_iPad.xib )的NIB文件视图,以及AppDelegate中的if语句确定要运行的内容-正是我想要的设置方式。

I wanted to add a 3rd & 4th tabs, so starting with the 3rd tab (doing 1 at a time) I created a new UIViewController subclass. 我想添加第3个和第4个标签,因此从第3个标签开始(一次做1个),我创建了一个新的UIViewController子类。 As it doesn't give the option to create both NIBs at once, I selected "Targeted for iPad", & had intended to create the iPhone NIB manually. 由于它没有一次创建两个NIB的选项,因此我选择了“ Targeted for iPad”,并且打算手动创建iPhone NIB。 I added a "_iPad" suffix to the created NIB file, then I created a user interface view NIB file to which I added the "_iPhone" suffix. 我在创建的NIB文件中添加了“ _iPad”后缀,然后在用户界面视图NIB文件中添加了“ _iPhone”后缀。 I then set up the code for the new view controller in the AppDelegate implementation file to include the 3rd view controller & tab, & I used the other view controller classes as a guide to set up the new class's code. 然后,我在AppDelegate实现文件中为新视图控制器设置代码,以包括第3个视图控制器和选项卡,并且我使用其他视图控制器类作为指导来设置新类的代码。

For the 3rd _iPhone NIB, I dragged a view object from the objects library onto the canvas, & set it up as per the other 2 _iPhone NIBs. 对于第三个_iPhone NIB,我将视图对象从对象库中拖动到画布上,并按照其他两个_iPhone NIB进行设置。 But when I went to connect the outlets, there is no view outlet in the referencing outlets of the connections panel to connect with, which I thought there should be. 但是当我去连接插座时,我认为应该连接的连接面板的参考插座中没有可视插座。 At this point I suspected something was wrong. 在这一点上,我怀疑出现了问题。

在此处输入图片说明

I tried running it in the simulator, in iPad mode it works fine (all 3 tabs are clickable). 我尝试在模拟器中运行它,在iPad模式下可以正常工作(所有3个选项卡均可单击)。 But in iPhone mode clicking the 3rd tab crashes it with a "SIGABRT" on thread 1. It's obvious what I did didn't work. 但是在iPhone模式下,单击第3个选项卡会使其崩溃,并在线程1上显示“ SIGABRT”。很明显,我没有执行任何操作。 I don't see anything in the output window that gives me any clues. 我在输出窗口中看不到任何提示。

Being a newbie to obj-c, so not being too sure of the problem, I would have thought that I either: 作为obj-c的新手,因此不太确定这个问题,我会以为我要么:

  • have used the wrong user interface template (view) 使用了错误的用户界面模板(查看)
  • should have used a view controller object from the object library (not a view) 应该使用了对象库中的视图控制器对象(不是视图)
  • or that I should have declared some outlets in my view controller class files. 或者我应该在我的视图控制器类文件中声明一些出口。

But if I should have done either of the latter 2, then my question would be why does the iPad NIB work then, when it clearly has a view object in the NIB & no outlets declared in the class files (same with the other 2 view controllers for both devices)? 但是,如果我应该完成后两个中的任何一个,那么我的问题是,为什么iPad NIB可以正常工作,当它在NIB中明显具有视图对象并且类文件中没有声明出口时(与其他2个视图相同)两个设备的控制器)?

Does the UITabView class somehow have outlets pre-declared within it for the first 2 tabs? UITabView类是否在前两个选项卡中以某种方式预先声明了插座? But that still doesn't explain why the _iPad NIB works. 但这仍不能解释_iPad NIB为何起作用。

As usual, any help & advice much appreciated, & if there's a link to an explanation somewhere that I've missed, please show me, because I'm happy to do the research. 像往常一样,任何帮助和建议都将不胜感激,并且如果有我想念的地方的解释链接,请告诉我,因为我很高兴进行研究。

If what I've done wrong here is not determinable, then I guess ultimately what I'm asking is a clue to how best to create the second NIB file for iPhone to mesh with the class created with iPad NIB. 如果我做错了什么是不确定的,那么我想我最终要问的是如何为iPhone创建第二个NIB文件以与使用iPad NIB创建的类相啮合的最佳线索。

Sorry to answer my own question but with further searching I found this answer that was the solution, although not quite the whole story. 很抱歉回答我自己的问题,但是通过进一步搜索,我发现这个答案是解决方案,尽管还不是全部。 So I thought to put what I did in an asnwer so others can refer to it. 因此,我想把我所做的事情总结一下,以便其他人可以参考。

在此处输入图片说明

As Piotr Czapla explains in the linked answer, for some reason Xcode doesn't populate the connectionRecords data, as you can see by my first red arrow. 正如Piotr Czapla在链接的答案中解释的那样,由于某些原因,Xcode不会填充connectionRecords数据,正如您通过我的第一个红色箭头所看到的那样。 Having a look at the view controller that works (where second red arrow is), that's what the data should look like. 看一下工作正常的视图控制器(第二个红色箭头在其中),这就是数据的外观。 So the answer is to cut the data & paste it into the NIB file, or type it. 因此,答案是剪切数据并将其粘贴到NIB文件中,或键入它。 You can do this in Xcode by right-clicking the NIB file in the project navigatior & then Open As > Source Code, which is what you see in my screenshots. 您可以在Xcode中执行此操作,方法是右键单击项目导航器中的NIB文件,然后单击“打开方式”>“源代码”,这就是您在屏幕快照中看到的内容。

The bit I want to add to Piotr Czapla's explanation though is the destination reference pointed to by the second red arrow might not be correct for the NIB file you're pasting into (mine wasn't) & Xcode might not let you go back into IB mode. 我想在Piotr Czapla的说明中添加的一点是,第二个红色箭头指向的目标引用可能与您要粘贴的NIB文件不正确(不是我的)并且Xcode可能不允许您返回IB模式。 If so, you need to get the correct reference from the IBUIView class within your NIB file, as pointed to by the third red arrow. 如果是这样,则需要从NIB文件中的IBUIView类获取正确的引用,如第三个红色箭头所指出的那样。 Once I copied that reference to my destination reference ref=, as shown by the fourth red arrow, all was ok & the problem was solved. 将引用复制到目标引用ref =后,如第四个红色箭头所示,一切正常,问题已解决。 I could then go back into IB mode (right click, Open As > Interface Builder - iOS) & the view works in the simulator. 然后,我可以返回到IB模式(右键单击,打开方式> Interface Builder-iOS),然后视图在模拟器中工作。

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

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