简体   繁体   English

已加载笔尖但未设置“查看”插座

[英]Loaded nib but the 'view' outlet was not set

I added a new nib file to my project, and tried to load it.我在我的项目中添加了一个新的 nib 文件,并尝试加载它。

However, when I click on the toolbar icon that is supposed to take me to the view that I created, I get an NSInternalInconsistencyException with the message:但是,当我单击应该带我进入我创建的视图的工具栏图标时,我收到一个NSInternalInconsistencyException消息:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "..." nib but the view outlet was not set.'由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“...”笔尖,但未设置视图出口。

So I opened up my nib file, and I see for the view that there are no referencing outlets set.所以我打开了我的 nib 文件,我看到没有设置引用插座的视图。 However, I try to click and drag the circle for "new referencing outlet" to File's Owner, but it won't let me...what do I need to do to get my view to display?但是,我尝试单击并将“新引用出口”的圆圈拖动到文件所有者,但它不会让我......我需要做什么才能显示我的视图?

Here's what worked for me:以下是对我有用的内容:

  • Open the XIB file causing problems打开导致问题的 XIB 文件
  • Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)单击左侧栏上的文件所有者图标(顶部一个,看起来像一个黄色的框)
  • If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar.如果您没有看到右侧边栏,请单击工具栏中“查看”上方的第三个图标。 This will show the right-hand sidebar这将显示右侧边栏
  • In the right-hand sidebar, click on the fourth tab--the one that looks a bit like a newspaper在右侧边栏中,单击第四个选项卡——看起来有点像报纸的选项卡
  • Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view.在顶部的“自定义类”下,确保 Class 是应与此视图对应的 ViewController 的名称。 If not, enter it如果没有,请输入
  • In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it在右侧边栏中,单击最后一个选项卡 - 看起来像一个带有箭头的圆圈的选项卡
  • You should see "outlets" with "view" under it.您应该会看到下面带有“view”的“outlets”。 Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline将旁边的圆圈拖到左侧栏上的“视图”图标(底部一个,看起来像一个带有粗灰色轮廓的白色方块
  • Save the xib and re-run保存xib并重新运行

This is Josh Justice proposal, but in a graphical way (pictures are mine):这是 Josh Justice 的提议,但以图形方式(图片是我的):

  1. Select File owner选择文件所有者
  2. On right hand side panel select custom class.在右侧面板上选择自定义类。
  3. Enter the custom class name输入自定义类名

在此处输入图片说明

  1. On right hand side panel select oultets在右侧面板上选择 oultets
  2. Drag view outlet to view component拖动视图出口查看组件

在此处输入图片说明

Finally the View Controller is instantiated with the rolling code:最后使用滚动代码实例化视图控制器:

        PTFilterUserVC *aFilterUserVC = [[PTFilterUserVC alloc] initWithNibName:@"FilterVC" bundle:nil];

        //OPTIONAL.This is how 'I' am interested in present the view controller.
        [self.navigationController pushViewController:aFilterUserVC animated:YES];

I can generally fix it by remaking the connection between File's Owner and the view.我通常可以通过重新建立文件所有者和视图之间的连接来修复它。 Control-drag from the File's owner to your View (in IB) and select view from the pop-up menu.按住 Control 键从文件所有者拖动到您的视图(在 IB 中),然后从弹出菜单中选择视图。

The View Identity - Class Identity was not set.未设置查看标识 - 类标识。 After setting it to the appropriate class, the issue was resolved.将其设置为适当的类后,问题就解决了。

Are you sure you have a UIView (or subclass) assigned to the "view" property of yourViewController?你确定你有一个 UIView (或子类)分配给 yourViewController 的“view”属性吗?

Right click on "File Owner" in the left pane of the xib for yourViewController and verify that the "view" outlet is set.在 yourViewController 的 xib 的左窗格中右键单击“文件所有者”,并验证“视图”插座已设置。 If not, set it to a view!如果没有,请将其设置为视图!

this will definetly fix the Issue这将明确解决问题

I had the same issue with XCode 4.6.3.我在 XCode 4.6.3 上遇到了同样的问题。 I had started out with a couple files named MySettingsView.h and .m but deleted them in favor of MySettingsViewController.h , but despite trying most of the hints mentioned here, it still kept erroring with,我一开始使用了几个名为MySettingsView.h.m文件,但为了支持MySettingsViewController.h删除了它们,但是尽管尝试了这里提到的大部分提示,它仍然不断出错,

2013-07-05 11:48:17.205 MyApp[39024:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MySettingsView" nib but the view outlet was not set.' 2013-07-05 11:48:17.205 MyApp[39024:c07] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“MySettingsView”nib 但视图插座没有设置。

It was evidently still "confused", trying to load MySettingsView.xib instead of MySettingsView Controller .xib.它显然仍然“困惑”,试图加载 MySettingsView.xib 而不是 MySettingsView Controller .xib。 Maybe its "do what I mean" logic is too fancy.也许它的“做我的意思”逻辑太花哨了。

So I worked around the problem by hardcoding the NIB/XIB name in MySettingsViewController.m:所以我通过在 MySettingsViewController.m 中硬编码 NIB/XIB 名称来解决这个问题:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"MySettingsViewController" bundle:nibBundleOrNil];
}

For me all the things stated here https://stackoverflow.com/a/6395750/939501 were true but still it was throwing error, reason was I created a View class with name ABCView and then deleted it later I added a view controller as ABCViewController so somehow it was referring to old ABCView in new view controller, I had to delete the ABCViewController and add a new one with different name that solved my issue.对我来说,这里所说的所有内容https://stackoverflow.com/a/6395750/939501都是正确的,但仍然抛出错误,原因是我创建了一个名为 ABCView 的 View 类,然后将其删除,我添加了一个视图控制器作为ABCViewController 所以不知何故它指的是新视图控制器中的旧 ABCView,我不得不删除 ABCViewController 并添加一个不同名称的新控制器来解决我的问题。

Thanks谢谢

To anyone that is using an xib method to create a UIView and having this problem, you will notice that you won't have the "view" outlet under the connections inspector menu.对于使用 xib 方法创建 UIView 并遇到此问题的任何人,您会注意到在连接检查器菜单下没有“视图”出口。 But if you set the File's Owners custom class to a UIViewController and then you will see the "view" outlet, which you can just CMND connect an outlet to the CustomView.但是,如果您将 File's Owners 自定义类设置为 UIViewController,然后您将看到“视图”插座,您只需通过 CMND 将插座连接到 CustomView。

I ran into this problem in a slightly different way from the other answers here.我遇到这个问题的方式与这里的其他答案略有不同。

If I simply created a new xib file, added a UIViewController to it in Interface Builder, and set that UIViewController's custom class to my view controller, that resulted in the "view outlet was not set" crash.如果我只是创建了一个新的 xib 文件,在 Interface Builder 中向它添加了一个 UIViewController,并将该 UIViewController 的自定义类设置为我的视图控制器,则会导致“未设置视图插座”崩溃。 The other solutions here say to control-drag the view outlet to the View, but for me the view outlet was greyed out and I couldn't control-drag it.这里的其他解决方案说控制拖动视图出口到视图,但对我来说视图出口是灰色的,我无法控制拖动它。

灰色的 View 插座

I figured out that my mistake was in adding a UIViewController in Interface Builder.我发现我的错误是在 Interface Builder 中添加了一个 UIViewController。 Instead, I had to add a UIView, and set the Custom Class of the File's Owner to my view controller.相反,我必须添加一个 UIView,并将文件所有者的自定义类设置为我的视图控制器。 Then I could control-drag the view outlet of the File's Owner to my new view UIView and everything worked as it should.然后我可以控制拖动文件所有者的视图出口到我的新视图 UIView 并且一切正常。

My issue with this was caused by having a duplicate nib in the class folder that did not have the view set.我的问题是由于在没有设置视图的类文件夹中有重复的笔尖引起的。 xcode seemed to be choosing one nib for a build and then the other the next time I built the project. xcode 似乎为构建选择了一个笔尖,然后在我下次构建项目时选择了另一个笔尖。 Just deleted the other one.刚刚删了另一个。 Looks good.看起来挺好的。 Doh!哦!

Just spent more than hour trying to find out why my view property is not set in my view controller upon initiating it from nib.刚刚花了一个多小时试图找出为什么我的视图属性没有在我的视图控制器中设置时从笔尖启动。 Remember to call "[super initWithNibName...]" inside your view controller's initWithNibName.请记住在视图控制器的 initWithNibName 中调用“[super initWithNibName...]”。

I just fixed this in mine.我刚刚在我的中修复了这个。 Large project, two files.大项目,两个文件。 One was "ReallyLargeNameView" and another was "ReallyLargeNameViewController"一个是“ReallyLargeNameView”,另一个是“ReallyLargeNameViewController”

Based on the 2nd answer chosen above, I decided I should clean my build.基于上面选择的第二个答案,我决定我应该清理我的构建。 Nada, but I was still suspect of XCode (as I have two identical classes, should abstract them but eh...) So one's working, one's not. Nada,但我仍然怀疑 XCode(因为我有两个相同的类,应该对它们进行抽象,但是呃......)所以一个在工作,一个没有。 File's owner names are so far as copy and pasted, outlets rehooked up, xCode rebooted, still nothing.文件的所有者名称是复制和粘贴的,插座重新连接,xCode 重新启动,仍然没有。

So I delete the similar named class (which is a view).所以我删除了类似的命名类(这是一个视图)。 Soon, new error "outlet inside not hooked up" literally was "webView not key value" blah... basically saying "Visual Studio's better".很快,新的错误“outlet inside not hooked up”字面意思是“webView not key value”等等……基本上是说“Visual Studio更好”。 Anyway... I erase the smaller named file, and bam, it works.无论如何......我删除了较小的命名文件,并且bam,它起作用了。

XCode is confused by similar-named files. XCode 被类似名称的文件混淆。 And the project is large enough to need rebooting a bit, that may be part of it.而且该项目足够大,需要重新启动一下,这可能是其中的一部分。

Wish I had a more technical answer than "XCode is confused", but well, xCode gets confused a lot at this point.希望我有一个比“XCode 很困惑”更技术性的答案,但是,在这一点上,xCode 很困惑。 Unconfused it the same way I'd help a little kid.就像我帮助一个小孩一样,不要混淆它。 It works now, :) Should benefit others if the above doesn't fix anything.它现在有效,:) 如果上述内容没有解决任何问题,应该会使其他人受益。

Always remember to clean your builds (by deleting off the simulator too)永远记住清理你的构建(通过删除模拟器)

The previous answers almost solved the problem for me, but the last step was missing.之前的答案几乎为我解决了问题,但缺少最后一步。

  1. Create a xib and swift file with the same name.创建一个同名的 xib 和 swift 文件。

添加视图和 Swift 文件

  1. Set the file owner to be the UIView subclass.将文件所有者设置为 UIView 子类。

在此处输入图片说明

  1. Drag an outlet from the View to the UIView subclass, name it "contentView"将一个插座从 View 拖到 UIView 子类中,将其命名为“contentView”

添加内容视图

  1. Add this custom initializer so when the xib loads it attaches the contentView添加此自定义初始值设定项,以便在 xib 加载时附加 contentView

将内容视图添加为子视图

required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        Bundle(for: self.classForCoder).loadNibNamed("SampleView", owner: self, options: nil)
        addSubview(contentView)
        contentView.frame = self.bounds
        contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
    }

Now any @IBOutlets you add will be attached.现在,您添加的任何 @IBOutlets 都将被附加。

Cheers, Richard干杯,理查德

我在不小心删除了 xib 引用并再次添加时遇到了同样的问题。我只是通过在文件所有者和视图之间建立连接来修复。还要确保您的 FilesOwner 的自定义类是您预期的 viewController。

I also had the same problem and my issue was that i added an other Localisation (English) to the ViewControllers nib so my App with the Localisation German could´t find the nib with the Localisation English!!我也遇到了同样的问题,我的问题是我向 ViewControllers 笔尖添加了其他本地化(英语),所以我的带有本地化德语的应用程序找不到带有本地化英语的笔尖! Hope this helps anybody!希望这可以帮助任何人!

For me, the problem was caused by calling initWithNibName:bundle: .对我来说,问题是由调用initWithNibName:bundle:引起的。 I am using table view cells from a nib file to define entry forms that sit on tableViews .我正在使用 nib 文件中的表格视图单元格来定义位于tableViews上的条目表单。 As I don't have a view, doesn't make sense to hook to one.由于我没有观点,因此与一个观点挂钩是没有意义的。 Instead, if I call the initWithStyle: method instead, and from within there, I load the nib file, then things work as expected.相反,如果我调用initWithStyle:方法,然后从那里加载 nib 文件,那么事情会按预期工作。

I had the same problem, but a slightly different solution was called for.我遇到了同样的问题,但需要一个稍微不同的解决方案。 The problem in this case was the class of the File Owner, rather than the class of the View.这种情况下的问题是文件所有者的类,而不是视图的类。 To set this, I had to click the "backwards play" icon in the lower left corner of the Interface Builder window, and options then appeared that isolated the characteristics of the File Owner, the First Responder, and the View.要设置它,我必须单击 Interface Builder 窗口左下角的“向后播放”图标,然后出现的选项将文件所有者、第一响应者和视图的特征隔离开来。 Clicking on the first one (a large transparent box), enabled me to then set its custom class as suggested above.单击第一个(一个大的透明框),使我能够按照上面的建议设置其自定义类。

I had the same problem, but a different solution was called for.我遇到了同样的问题,但需要不同的解决方案。 The problem in this case was the class of the File Owner was not connected to xib file.这种情况下的问题是文件所有者的类没有连接到 xib 文件。

I ran into something very similar tonight, with a Swift UIViewController subclass.今晚我遇到了非常相似的事情,使用 Swift UIViewController 子类。 In this case, none of the above fixes worked, but reordering my code a bit did.在这种情况下,上述修复均无效,但对我的代码进行了一些重新排序。 Net-net, having an extension to the subclass occur before the subclass's definition itself in the same file seems to confuse XCode, despite compiling fine; Net-net,在同一文件中的子类定义本身之前发生子类的扩展似乎混淆了 XCode,尽管编译良好; the fix was to place the extensions after the subclass's definition.解决方法是将扩展放在子类的定义之后。

I've posted the details in an answer to this similar question .我已经在这个类似问题的回答中发布了详细信息。

In my case , the designated initializer - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil in ***ViewController class was implemented so even if when I call other initializer to initialize the object ,the designated initializer will be called .在我的例子中,指定的初始化器- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil在 ***ViewController 类中实现了所以即使当我调用其他初始化器来初始化对象时,指定的初始化器也会叫做 。

So to resolve this problem checking wether the - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil is also a proper way.因此,要解决此问题,检查- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil是否也是一种正确的方法。

My problem was in wrong classes.我的问题出在错误的课程上。 I used custom .xib for my custom view.我使用自定义 .xib 作为我的自定义视图。 Correctly it has to be set like here:正确地它必须像这样设置:

  1. View shouldn't have a class视图不应该有一个类
  2. Class which is used with the .xib is set in File's Owner tab.xib一起使用的类在File's Owner选项卡中设置
  3. Outlets are connected to File's Owner and not to the View . Outlets 连接到File's Owner而不是View

    图片

Just had the same error in my project, but different reason.只是在我的项目中出现了同样的错误,但原因不同。 In my case I had an IBOutlet setup with the name "View" in my custom UITableViewController class.就我而言,我的自定义 UITableViewController 类中有一个名为“View”的 IBOutlet 设置。 I knew "view" was special because that is a member of the base class, but I didn't think View (different case) would also be a problem.我知道“view”很特别,因为它是基类的成员,但我不认为 View(不同情况)也会成为问题。 I guess some areas of Cocoa are not case-sensitive, and probably loading a xib is one of those areas.我猜 Cocoa 的某些区域不区分大小写,并且加载 xib 可能就是这些区域之一。 So I just renamed it to DefaultView and all is good now.所以我只是将它重命名为 DefaultView,现在一切都很好。

select the files owner and goto open the identity inspecter give the class name to which it corresponds to.选择文件所有者并打开身份检查器,给出它对应的类名。 If none of the above methods works and still you can't see the view outlet then give new referencing outlet Connection to the File's Owner then you can able to see the view outlet.如果上述方法均无效,并且您仍然看不到视图插座,则为文件所有者提供新的引用插座连接,然后您就可以看到视图插座。 Click on the view Outlet to make a connection between the View Outlet and File's owner.单击视图出口以在视图出口和文件所有者之间建立连接。 Run the Application this works fine.运行应用程序这工作正常。

In my case, the view was not viewed in xib.就我而言,该视图未在 xib 中查看。 in xib the View was size = none (4th tab right hand).在 xib 中,视图大小为 = 无(右侧第 4 个选项卡)。 I set size to Freeform and reload xCode.我将大小设置为 Freeform 并重新加载 xCode。 view was appealed and I set the proper link to View.视图被上诉,我设置了正确的视图链接。

If you have tried everything and you still get this error, try re-creating the class file from scratch but remember to select the "Also create XIB file" check box.如果您已经尝试了所有方法但仍然出现此错误,请尝试从头开始重新创建类文件,但请记住选中“同时创建 XIB 文件”复选框。 This will auto link up a few items that are not linked when creating these files separately.这将自动链接一些单独创建这些文件时未链接的项目。 After this is created, you can likely cut and paste everything onto the new XIB and it should work fine.创建后,您可以将所有内容剪切并粘贴到新的 XIB 上,它应该可以正常工作。

I am finding this issue specifically with creating files separately in Swift.我在 Swift 中单独创建文件时发现了这个问题。

for me it happened, when对我来说它发生了,当

  • I have a ViewController class ( .mm/h ) associated with the Nib file,我有一个与 Nib 文件关联的 ViewController 类( .mm/h ),
  • UIView from this ViewController has to be loaded on the another view as a subview,来自这个 ViewController 的UIView必须作为子视图加载到另一个视图上,

  • we will call something like this我们会这样称呼

    -(void)initCheckView{ CheckView *pCheckViewCtrl = [CheckView instance]; pCheckView = [pCheckViewCtrl view]; [[self view]addSubview:pCheckView]; [pCheckViewCtrl performCheck]; }

Where在哪里

+(CheckView *)instance{
    static CheckView *pCheckView = nil;
    static dispatch_once_t checkToken;

    dispatch_once(&checkToken, ^{
        pCheckView = [[CheckView alloc]initWithNibName:@"CheckView" bundle:nil];
        if ( pCheckView){
            [pCheckView initLocal];
            **[pCheckView loadView];**
        }
    });

    return pCheckView;

}

Here loadView was missing,,, adding this line resolved my problem.这里缺少 loadView,添加这一行解决了我的问题。

I had the same problem, I figured out and it is because of i had ticked " Static cells " in the properties of Table View under Content option .我遇到了同样的问题,我想通了,这是因为我在内容选项下的表视图属性中勾选了“静态单元格”。 Worked when it changed to " Dynamic Prototypes ".当它更改为“ Dynamic Prototypes ”时Dynamic Prototypes Screenshot is below.截图如下。 在此处输入图片说明

我在 Xcode 9.3 上遇到了类似的问题,将“文件所有者”属性检查器下的“模块”设置为项目模块为我解决了这个问题。

打开 viewController 所在的故事板文件,或使用textEdit.app 的XIB相关文件,并检查故事板或 XIB 名称是否与您的 viewController 相同,然后更改它,保存并重新加载/重新启动 Xcode。

If you're using a custom init method, check that you're returning something valid.如果您使用自定义 init 方法,请检查您返回的内容是否有效。 I ran into a piece of code that crashed on something like this:我遇到了一段代码,它在这样的事情上崩溃了:

- (id)init {
   self = [super init];
   if (self) {
      CustomController *controller = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil];
   } return self;
}

In another class, the controller was created like so:在另一个类中,控制器是这样创建的:

CustomController *controller = [[CustomController alloc] init];

The problem is that in the init method, self hasn't changed and should look like this instead:问题是在 init 方法中, self 没有改变,而是应该是这样的:

- (id)init {
   self = [super init];
   if (self) {
      CustomController *controller = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil];
      [controller viewDidLoad];
      self = controller;
   } return self;
}

I'd like to second Stephen J. Some times X Code does just get confused. 我想支持StephenJ。有时候X代码确实很混乱。 I just had an experience where I had played around with the UI a lot, and had added and deleted outlets quite a few times. 我刚刚经历了很多使用UI的经历,并多次添加和删除了网点。 The outlets just would not wire-up any more. 插座将不再接线。 I never did figure out a specific reason (I had tried all the solutions above), and I just had to delete the NIB and recreate it from scratch, and in fact had to use a different name for the NIB before it would work. 我从来没有弄清楚具体的原因(我已经尝试了上面的所有解决方案),而我只需要删除NIB并从头开始重新创建它,实际上,在NIB起作用之前,必须使用其他名称。 (XCode 4.6.1) Wasted a couple of hours on that. (XCode 4.6.1)为此浪费了几个小时。

When you have a Swift code that references different namespace with @objc , be sure to use the Objective-C class name: 当您有一个使用@objc引用不同名称空间的Swift代码时,请确保使用Objective-C类名称:

@objc(NamespacedSomeViewController)
class SomeViewController: UIViewController {
....

In this case, you need to use NamespacedSomeViewController in the IB. 在这种情况下,您需要在IB中使用NamespacedSomeViewController

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

相关问题 已加载笔尖但未设置视图插座 - Swift 版 - Loaded nib but the view outlet was not set - Swift edition “加载的笔尖,但视图插座没有设置”例外 - “loaded nib but the view outlet was not set” exception 加载了nib文件,但未设置视图插座 - Loaded the nib file but the view outlet was not set 加载的笔尖但未设置视图插座 - UITableViewController - Loaded nib but the view outlet was not set - UITableViewController iOS Framework-已加载笔尖,但未设置视图出口 - iOS Framework - Loaded the nib but the view outlet was not set iOS帮助:加载笔尖但未设置视图插座 - iOS Help: loaded the nib but the view outlet was not set UIViewController _loadViewFromNibNamed:bundle:加载了“View”笔尖,但未设置视图插座。 - UIViewController _loadViewFromNibNamed:bundle: loaded the “View” nib but the view outlet was not set.' “加载了”XXX“笔尖,但未设置视图插座。” - 再次 - “loaded the ”XXX“ nib but the view outlet was not set.” - again 以编程方式创建的UIViewController在“已加载笔尖但未设置视图出口”时崩溃 - Programmatically-created UIViewController crash on “loaded nib but the view outlet was not set” 已装入笔尖,但未设置视图插座,无法找到视图插座。 - loaded the nib but the view outlet was not set, can't find a view outlet.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM