因为我之前先创建了一个ViewController。后来,因为某些原因,我需要添加一个xib文件,与ViewController绑定,但是在绑定过程中出现了以下的问题。
1.最初的做法

出现的问题:在进入该ViewController的时候,直接发生了崩溃。崩溃日志如下:
****** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ZhiBoController" nib but the view outlet was not set.'***
2.错误的处理
经过网上的搜索,是要将File's Owner 设置class,然后给view,接着就照做,如下图:

步骤1

步骤2
处理完之后,在进入该ViewController的时候,还是会崩溃,崩溃日志如下:
****** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .'***
3.继续崩溃之后,我就想着可以先直接创建出来一个带有xib的ViewController对比一下,看看哪里不一样。然后自己创建了一个带有xib的ViewController,然后对比了一下,发现了两者的不同

这个是自己创建的xib

这个是直接创建的带有xib的controller的xib
原来在单独创建xib的时候,不能再创建controller了,只能创建UIView,至此,此问题已解决。
网友评论