简体   繁体   English

如何在 iPhone SDK 中使用标签栏 controller 设置查看出口

[英]How to set view outlet using tab bar controller in iPhone SDK

I created a simple tab bar application in Xcode.我在 Xcode 中创建了一个简单的标签栏应用程序。

The default tab bar has 2 tab bar items.默认选项卡栏有 2 个选项卡栏项目。 I add a third tab bar item and set its view controller attribute to a view i had created and subsequently saved called ThirdView.xib.我添加了第三个标签栏项目并将其视图 controller 属性设置为我创建并随后保存的名为 ThirdView.xib 的视图。

When I try to run, the first two default tabs work fine.当我尝试运行时,前两个默认选项卡工作正常。 The third one I added throws this error:我添加的第三个引发了这个错误:

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ThirdView" nib but 
the view outlet was not set.'

I apologize as I'm a huge iPhone-SDK n00b, but no manner of clicking and dragging and control-click dragging is allowing me to set the view outlet on the third view I had created.我很抱歉,因为我是一个巨大的 iPhone-SDK n00b,但是没有任何点击和拖动以及控制点击拖动的方式允许我在我创建的第三个视图上设置视图出口。

I had similar problem 10 mins ago, it was unsaved xib file:). 10分钟前我遇到了类似的问题,它是未保存的xib文件:)。 For some reasons XCode doesn't ask to save xib files when one hit run.由于某些原因,XCode 在一次运行时不会要求保存 xib 文件。

But if that isn't the case, I would double check if the view is indeed connected in the xib file.但如果不是这种情况,我会仔细检查视图是否确实连接在 xib 文件中。

To do so open ThirdView.xib as plain text file (right click > open as > plain text file) and search for text: ">view<".为此,将 ThirdView.xib 作为纯文本文件打开(右键单击 > 打开为 > 纯文本文件)并搜索文本:">view<"。 If the view is connected you should find something similar to the code below:如果视图已连接,您应该会找到类似于以下代码的内容:

<object class="IBConnectionRecord">
    <object class="IBCocoaTouchOutletConnection" key="connection">
        <string key="label">view</string>
        <reference key="source" ref="372490531"/>
        <reference key="destination" ref="191373211"/>
    </object>
    <int key="connectionID">15</int>
</object>

If you can't find it this could mean that the problem is caused by a bug in Interface Builder.如果您找不到它,这可能意味着问题是由 Interface Builder 中的错误引起的。 Then you can try to add the connection by hand.然后您可以尝试手动添加连接。 Let me know if that is the case.让我知道是否是这种情况。

Check the filename you're passing to initFromNib (or however you're loading the controller).检查您传递给 initFromNib 的文件名(或者您正在加载控制器)。 A typo or including the extension can result in this message.拼写错误或包含扩展名可能会导致此消息。

Using XCode 4, I got this error because I did not set the NIB name for the "Third" button on the Tab Bar Controller.使用 XCode 4,我收到此错误,因为我没有为选项卡栏 Controller 上的“第三”按钮设置 NIB 名称。 I fixed it by selecting the "Third" button, not the tab bar item within the button, and using the Attributes Inspector I set the NIB name.我通过选择“第三”按钮而不是按钮内的选项卡栏项目来修复它,并使用属性检查器设置了 NIB 名称。

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

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