简体   繁体   English

使用iOS 7的Xcode 5中的NSInternalInconsistencyException:'故事板:容器视图中有意外的子视图。

[英]NSInternalInconsistencyException in Xcode 5 with iOS 7: 'Story Board: There are unexpected subviews in the container view.'

I just installed Xcode 5.0.2 with OS X Mavericks. 我刚刚在OS X Mavericks中安装了Xcode 5.0.2。 When running my project which is originally built for iOS 5.1 on Xcode 4.5 I get the 'NSInternalInconsistencyException' error as shown below: 在Xcode 4.5上运行最初为iOS 5.1构建的项目时,我收到'NSInternalInconsistencyException'错误,如下所示:

*** Assertion failure in -[UIStoryboardEmbedSegue perform],    
/SourceCache/UIKit_Sim/UIKit-2903.23/UIStoryboardEmbedSegue.m:19

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'There are unexpected subviews in the container view.  
Perhaps the embed segue has already fired once or 
a subview was added programmatically?'

What I did was to solve any warnings displayed that are related to deprecated APIs, however I am still facing this problem. 我所做的是解决显示的与已弃用的API相关的任何警告,但我仍然面临这个问题。

My Questions are: 我的问题是:

  • How do I identify which storyboard scene is responsible for the issue? 如何确定哪个故事板场景对此问题负责?
  • Also, is there any recommended approach to solve this problem? 此外,是否有任何建议的方法来解决这个问题?

Note: I noticed I am using iOS 7 in xCode 5 as a base SDK while it used to be iOS 6 on xCode 4.5, but the deployment target was set to 6.0 in both. 注意:我注意到我在xCode 5中使用iOS 7作为基本SDK,而它曾经是xCode 4.5上的iOS 6,但部署目标在两者中都设置为6.0。 Changing the deployment target in Xcode 5 to other SDK versions did not fix the issue. 将Xcode 5中的部署目标更改为其他SDK版本并未解决此问题。

Note 2: I noticed the issue does not happen when running on Xcode 4.5 on iPhone Simulator for iOS 6 and the Base SDK is set to iOS 6.0. 注意2:我注意到在iPhone 6的iPhone模拟器上运行Xcode 4.5并且Base SDK设置为iOS 6.0时没有发生此问题。

Storyboard Screenshot 故事板截图 故事板截图(样本) The Table View Controller has a container view with an 'embed segue' to a view controller. Table View Controller有一个容器视图,其中一个'embed segue'指向一个视图控制器。

I figured it out. 我想到了。

How I had my UI 我如何拥有自己的UI

I am creating a universal app for both iPhone and iPad with a storyboard for each of these devices. 我正在为iPhone和iPad创建一个通用应用程序,每个设备都有一个故事板。 I had a tab bar controller connected to a navigation controller which is then connected to a UITableViewController which displays a table in a static cell (in order to have the top rows displayed with the titles). 我有一个连接到导航控制器的标签栏控制器,然后连接到UITableViewController,它在静态单元格中显示一个表格(为了让顶部行显示标题)。 Inside this UITableViewController I had a container view (which was set with a custom class MyApp_UITableViewCell) which displayed many dynamic rows. 在这个UITableViewController里面,我有一个容器视图(使用自定义类MyApp_UITableViewCell设置),它显示了许多动态行。

The cause 原因

The issue was caused because of the container view that was set to have the custom class as : MyApp_BIUiTableViewCell. 该问题是由于容器视图设置为将自定义类设置为:MyApp_BIUiTableViewCell引起的。 By removing the reference to this custom class in the storyboard the issue was removed 通过删除故事板中对此自定义类的引用,问题已被删除

How I solved it 我是怎么解决的

  1. Changed the base SDK and Deployment Target to be iOS 7. 将基本SDK和部署目标更改为iOS 7。

  2. In the storyboards for each device: I removed the reference custom cell in the identity inspector for each container view (which was set as MyApp_UITableViewCell) 在每个设备的故事板中:我在身份检查器中为每个容器视图(已设置为MyApp_UITableViewCell)删除了引用自定义单元格

My Recommendations 我的建议

For similar issues what I can say is to check the custom classes set and try to remove ones (one by one). 对于类似的问题,我可以说是检查自定义类集并尝试删除(逐个)。 Also, try commenting out each viewDidload and viewDidappear contents and see where the issue is being caused. 此外,尝试注释掉每个viewDidload和viewDidappear内容,并查看导致问题的位置。

If anyone else stumbles on this here is my story: 如果其他人偶然发现这是我的故事:

After merging my Swift2 feature branch into my Swift3 branch I got this error. 将我的Swift2功能分支合并到我的Swift3分支后,我收到了这个错误。

I had a ContainerView in my Storyboard. 我在Storyboard中有一个ContainerView。 I added an outlet for this ContainerView to my ViewController. 我为这个ContainerView添加了一个插座给我的ViewController。 After that I created an override and added a breakpoint to the following method: 之后我创建了一个覆盖并为以下方法添加了一个断点:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?)

When the breakpoint was hit, I checked how many subviews the ContainerView has by executing the following in the console. 当断点被击中时,我通过在控制台中执行以下操作来检查ContainerView有多少个子视图。

po containerView.subViews

This told me that my ContainerView already had one subview of the type UIVisualEffectBackdropView (or with a similar name). 这告诉我,我的ContainerView已经有一个UIVisualEffectBackdropView类型的子视图(或具有类似的名称)。

So I checked my ContainerView again and realized that the custom class that it was assigned to was of type UIVisualEffectView. 所以我再次检查了我的ContainerView,并意识到它所分配的自定义类是UIVisualEffectView类型。 This apparently caused it to automatically add the backdropView and thus making it incompatible with the assertion that in the end raises the error. 这显然导致它自动添加了backdropView,从而使它与最终引发错误的断言不兼容。 All I had to do was not inheriting from UIVisualEffectView but from a normal UIView. 我所要做的就是不是从UIVisualEffectView继承而是从普通的UIView继承。 Of course to achieve the visual effect I have to add it to the ViewController that the ContainerView is embedding. 当然为了实现视觉效果,我必须将它添加到ContainerView嵌入的ViewController中。

Hope this helps saving somebody from a headache :) 希望这有助于避免让人头疼:)

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

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