笔尖已加载,但“视图”却无法显示。插座未设置

发布于 2024-10-13 11:39:49 字数 393 浏览 5 评论 0原文

我向我的项目添加了一个新的 nib 文件,并尝试加载它。

但是,当我单击应该将我带到我创建的视图的工具栏图标时,我收到一个带有以下消息的 NSInternalInconsistencyException

由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“...”笔尖,但未设置视图出口。'

所以我打开了我的 nib 文件,我看到视图中没有设置引用插座。但是,我尝试单击“新引用出口”的圆圈并将其拖动到文件所有者,但它不允许我...我需要做什么才能显示我的视图?

I added a new nib file to my project, and tried to load it.

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:

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

So I opened up my nib file, and I see for the view that there are no referencing outlets set. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

讽刺将军 2024-10-20 11:39:50

我在 XCode 4.6.3 上遇到了同样的问题。我一开始有几个名为 MySettingsView.h.m 的文件,但删除了它们,转而使用 MySettingsViewController.h,但尽管尝试了大多数这里提到的提示中,它仍然不断出错,

2013-07-05 11:48:17.205 MyApp[39024:c07] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:
'-[UIViewController _loadViewFromNibNamed:bundle:] 加载了
“MySettingsView”笔尖,但未设置视图出口。'

显然它仍然“困惑”,试图加载 MySettingsView.xib 而不是 MySettingsView Controller.xib。也许“按我的意思做”的逻辑太花哨了。

因此,我通过在 MySettingsViewController.m 中硬编码 NIB/XIB 名称来解决这个问题:

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

I had the same issue with 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,

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.'

It was evidently still "confused", trying to load MySettingsView.xib instead of 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:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"MySettingsViewController" bundle:nibBundleOrNil];
}
廻憶裏菂餘溫 2024-10-20 11:39:50

对于使用 xib 方法创建 UIView 并遇到此问题的任何人,您会注意到连接检查器菜单下没有“视图”出口。但是,如果您将 File's Owners 自定义类设置为 UIViewController,那么您将看到“view”插座,您可以通过 CMND 将插座连接到 CustomView。

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. 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.

心清如水 2024-10-20 11:39:50

我的问题是由于类文件夹中存在重复的笔尖而没有设置视图而引起的。 xcode 似乎选择一个笔尖进行构建,然后在下次构建项目时选择另一个笔尖。刚刚删除了另一张。看起来不错。哎哟!

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. Just deleted the other one. Looks good. Doh!

悸初 2024-10-20 11:39:50

只是花了一个多小时试图找出为什么我的视图属性在我的视图控制器中从笔尖启动时没有设置。请记住在视图控制器的 initWithNibName 中调用“[super initWithNibName...]”。

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.

南城追梦 2024-10-20 11:39:50

我刚刚修复了这个问题。大项目,两个文件。一个是“ReallyLargeNameView”,另一个是“ReallyLargeNameViewController”

根据上面选择的第二个答案,我决定应该清理我的构建。 Nada,但我仍然怀疑 XCode(因为我有两个相同的类,应该抽象它们,但是呃......)所以一个在工作,一个不工作。文件的所有者名称被复制和粘贴,插座重新连接,xCode 重新启动,仍然没有。

所以我删除了类似的命名类(这是一个视图)。很快,新的错误“outlet inside not hooked up”字面意思是“webView not key value”等等……基本上是说“Visual Studio 更好”。无论如何...我删除了较小的命名文件,然后,它起作用了。

XCode 会被名称相似的文件混淆。而且该项目足够大,需要重新启动一下,这可能是其中的一部分。

希望我有一个比“XCode 很困惑”更技术性的答案,但是,xCode 在这一点上很困惑。就像我帮助一个小孩一样,不要混淆它。它现在可以工作了,:)如果上述方法不能解决任何问题,应该会让其他人受益。

永远记住清理你的构建(也删除模拟器)

I just fixed this in mine. Large project, two files. One was "ReallyLargeNameView" and another was "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. File's owner names are so far as copy and pasted, outlets rehooked up, xCode rebooted, still nothing.

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". Anyway... I erase the smaller named file, and bam, it works.

XCode is confused by similar-named files. 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. 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)

暮色兮凉城 2024-10-20 11:39:50

前面的答案几乎解决了我的问题,但缺少最后一步。

  1. 创建一个同名的 xib 和 swift 文件。

添加视图并Swift File

  1. 将文件所有者设置为 UIView 子类。

输入图像描述这里

  1. 从View中拖一个outlet到UIView子类中,命名为“contentView”

add the contentview

  1. 添加此自定义初始值设定项,以便在 xib 加载时附加 contentView

将 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]
    }

现在您添加的任何 @IBOutlets 都将被附加。

干杯,
理查德

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.

Add View and Swift File

  1. Set the file owner to be the UIView subclass.

enter image description here

  1. Drag an outlet from the View to the UIView subclass, name it "contentView"

add the contentview

  1. Add this custom initializer so when the xib loads it attaches the contentView

add the contentview as a subview

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.

Cheers,
Richard

木格 2024-10-20 11:39:50

我也遇到了同样的问题,我的问题是我向 ViewControllers 笔尖添加了其他本地化(英语),因此我的具有本地化德语的应用程序无法找到具有本地化英语的笔尖!希望这对任何人都有帮助!

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!! Hope this helps anybody!

浅浅淡淡 2024-10-20 11:39:50

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

I had face the same problem while accidentally deleted xib reference and added it again.I just fixed by making connection between Files owner and the view.Also make sure that your FilesOwner's custom class is your expected viewController.

霊感 2024-10-20 11:39:50

对我来说,问题是由调用 initWithNibName:bundle: 引起的。我使用 nib 文件中的表视图单元格来定义位于 tableViews 上的条目表单。因为我没有观点,所以挂钩没有意义。相反,如果我调用 initWithStyle: 方法,并从该方法中加载 nib 文件,那么事情就会按预期进行。

For me, the problem was caused by calling initWithNibName:bundle:. I am using table view cells from a nib file to define entry forms that sit on 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.

追风人 2024-10-20 11:39:50

我遇到了同样的问题,但需要一个稍微不同的解决方案。本例中的问题是文件所有者的类,而不是视图的类。要进行此设置,我必须单击 Interface Builder 窗口左下角的“向后播放”图标,然后出现选项,隔离文件所有者、第一响应者和视图的特征。单击第一个(一个大的透明框),使我能够按照上面的建议设置其自定义类。

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. Clicking on the first one (a large transparent box), enabled me to then set its custom class as suggested above.

情释 2024-10-20 11:39:50

我遇到了同样的问题,但需要不同的解决方案。本例中的问题是文件所有者的类未连接到 xib 文件。

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.

静若繁花 2024-10-20 11:39:50

今晚我遇到了非常相似的事情,有一个 Swift UIViewController 子类。在这种情况下,上述修复都不起作用,但对我的代码进行了一些重新排序。 Net-net,在同一文件中的子类定义本身之前出现子类的扩展似乎会使 XCode 感到困惑,尽管编译得很好;修复方法是将扩展放在子类的定义之后。

我已在对此类似问题的回答中发布了详细信息。

I ran into something very similar tonight, with a Swift UIViewController subclass. 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; the fix was to place the extensions after the subclass's definition.

I've posted the details in an answer to this similar question.

过期以后 2024-10-20 11:39:50

就我而言,***ViewController 类中的指定初始化程序 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 已实现,因此即使当我调用其他初始化程序进行初始化时对象,指定的初始化器将被调用。

因此,要解决此问题,请检查 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 是否也是正确的方法。

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 .

So to resolve this problem checking wether the - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil is also a proper way.

就此别过 2024-10-20 11:39:50

我的问题是上错课了。我使用自定义 .xib 作为自定义视图。
正确地,它必须像这样设置:

  1. 视图不应该有一个
  2. .xib 一起使用的类在 File's Owner 选项卡中设置
  3. 插座已连接到文件所有者,而不是视图

    pic

My problem was in wrong classes. I used custom .xib for my custom view.
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
  3. Outlets are connected to File's Owner and not to the View.

    pic

夏天碎花小短裙 2024-10-20 11:39:50

我的项目中出现了同样的错误,但原因不同。就我而言,我在自定义 UITableViewController 类中有一个名为“View”的 IBOutlet 设置。我知道“视图”很特殊,因为它是基类的成员,但我不认为视图(不同情况)也会成为问题。我猜 Cocoa 的某些区域不区分大小写,加载 xib 可能就是其中之一。所以我只是将其重命名为 DefaultView,现在一切都很好。

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. 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. I guess some areas of Cocoa are not case-sensitive, and probably loading a xib is one of those areas. So I just renamed it to DefaultView and all is good now.

天涯沦落人 2024-10-20 11:39:50

选择文件所有者并转到打开身份检查器,给出其对应的类名。如果上述方法都不起作用,并且您仍然看不到视图出口,则向文件所有者提供新的引用出口连接,然后您就可以看到视图出口。单击视图出口以在视图出口和文件所有者之间建立连接。运行应用程序,效果很好。

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.

无言温柔 2024-10-20 11:39:50

就我而言,该视图未在 xib 中查看。
在 xib 中,视图大小 = 无(右侧第四个选项卡)。我将大小设置为“自由格式”并重新加载 xCode。
view 被上诉,我设置了正确的 View 链接。

In my case, the view was not viewed in xib.
in xib the View was size = none (4th tab right hand). I set size to Freeform and reload xCode.
view was appealed and I set the proper link to View.

忆悲凉 2024-10-20 11:39:50

如果您已尝试了所有方法但仍然收到此错误,请尝试从头开始重新创建类文件,但请记住选中“同时创建 XIB 文件”复选框。这将自动链接一些单独创建这些文件时未链接的项目。创建后,您可以将所有内容剪切并粘贴到新的 XIB 上,它应该可以正常工作。

我在 Swift 中单独创建文件时发现了这个问题。

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. 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.

I am finding this issue specifically with creating files separately in Swift.

何必那么矫情 2024-10-20 11:39:50

对我来说,当

  • 我有一个与 Nib 文件关联的 ViewController 类( .mm/h )时,
  • 此 ViewController 中的

    UIView 必须作为子视图加载到另一个视图上,< /p>

  • 我们将调用类似的内容

    -(void)initCheckView{
    
       CheckView *pCheckViewCtrl = [CheckView 实例];
    
       pCheckView = [pCheckViewCtrl视图];
    
       [[自身视图]addSubview:pCheckView];
    
       [pCheckViewCtrl执行检查];        
    
    }
    

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,,,添加这一行解决了我的问题。

for me it happened, when

  • I have a ViewController class ( .mm/h ) associated with the Nib file,
  • UIView from this ViewController has to be loaded on the another view as a subview,

  • 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.

半仙 2024-10-20 11:39:50

我遇到了同样的问题,我发现这是因为我在内容选项下的表格视图属性中勾选了“静态单元格” >。当它更改为“动态原型”时有效。截图如下。
输入图片此处描述

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". Screenshot is below.
enter image description here

流年里的时光 2024-10-20 11:39:50

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

I had a similar problem with Xcode 9.3, and setting "Module" under the "File Owner's" attribute inspector to the project module fixed this for me.

三人与歌 2024-10-20 11:39:50

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

Open your storyboard file where your viewController exists, or XIB related file with textEdit.app and check if the storyboard or XIB name is the same of your viewController, then change it, save and reload/restart Xcode.

浊酒尽余欢 2024-10-20 11:39:50

如果您使用自定义 init 方法,请检查您返回的内容是否有效。我遇到了一段代码,它崩溃了,如下所示:

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

在另一个类中,控制器是这样创建的:

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

问题是在 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;
}

If you're using a custom init method, check that you're returning something valid. 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:

- (id)init {
   self = [super init];
   if (self) {
      CustomController *controller = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(className) owner:self options:nil];
      [controller viewDidLoad];
      self = controller;
   } return self;
}
浅唱々樱花落 2024-10-20 11:39:49

以下是对我有用的方法:

  • 打开导致问题的 XIB 文件
  • 单击左侧栏上的文件所有者图标(顶部的一个,看起来像一个黄色框)
  • 如果您没有看到右侧边栏,请单击上面的第三个图标工具栏中的“查看”。这将显示右侧边栏
  • 在右侧边栏中,单击第四个选项卡 - 看起来有点像报纸的选项卡
  • 在顶部的“自定义类”下,确保 Class 是该 ViewController 的名称应该对应这个观点。如果没有,请输入它
  • 在右侧边栏中,单击最后一个选项卡 - 看起来像一个带有箭头的圆圈的选项卡
  • 您应该会看到“outlet”,其下方带有“view”。将旁边的圆圈拖到左栏上的“查看”图标(底部的一个,看起来像一个带有粗灰色轮廓的白色方块)
  • 保存 xib 并重新运行

Here's what worked for me:

  • Open the XIB file causing problems
  • 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. 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. 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
草莓味的萝莉 2024-10-20 11:39:49

这是 Josh Justice 的提案,但以图形方式(图片是我的):

  1. 选择文件所有者
  2. 在右侧面板上选择自定义类。
  3. 输入自定义类名称

在此处输入图像描述

  1. 在右侧面板上选择 ultets
  2. 拖动视图出口以查看组件

在此处输入图像描述

最后,使用滚动代码实例化视图控制器:

        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];

This is Josh Justice proposal, but in a graphical way (pictures are mine):

  1. Select File owner
  2. On right hand side panel select custom class.
  3. Enter the custom class name

enter image description here

  1. On right hand side panel select oultets
  2. Drag view outlet to view component

enter image description here

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];
玩世 2024-10-20 11:39:49

我通常可以通过重新建立文件所有者和视图之间的连接来修复它。按住 Control 键并从文件所有者拖动到视图(在 IB 中),然后从弹出菜单中选择视图。

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.

童话 2024-10-20 11:39:49

未设置视图标识 - 类标识。将其设置为适当的类后,问题就解决了。

The View Identity - Class Identity was not set. After setting it to the appropriate class, the issue was resolved.

记忆消瘦 2024-10-20 11:39:49

您确定您已将 UIView (或子类)分配给您的ViewController 的“view”属性吗?

右键单击 ViewController 的 xib 左侧窗格中的“文件所有者”,并验证是否已设置“视图”出口。
如果没有,请将其设置为视图!

这肯定会解决问题

Are you sure you have a UIView (or subclass) assigned to the "view" property of yourViewController?

Right click on "File Owner" in the left pane of the xib for yourViewController and verify that the "view" outlet is set.
If not, set it to a view!

this will definetly fix the Issue

dawn曙光 2024-10-20 11:39:49

我遇到这个问题的方式与这里的其他答案略有不同。

如果我只是创建一个新的 xib 文件,在 Interface Builder 中向其中添加 UIViewController,并将该 UIViewController 的自定义类设置为我的视图控制器,则会导致“未设置视图出口”崩溃。这里的其他解决方案说将视图出口控制拖动到视图,但对我来说,视图出口呈灰色,我无法控制拖动它。

灰色- out Viewoutlet

我发现我的错误是在 Interface Builder 中添加 UIViewController 。相反,我必须添加一个 UIView,并将文件所有者的自定义类设置为我的视图控制器。然后我可以控制拖动文件所有者的视图出口到我的新视图 UIView ,一切都按预期工作。

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. 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.

the greyed-out View outlet

I figured out that my mistake was in adding a UIViewController in Interface Builder. Instead, I had to add a UIView, and set the Custom Class of the File's Owner to my view controller. Then I could control-drag the view outlet of the File's Owner to my new view UIView and everything worked as it should.

翻身的咸鱼 2024-10-20 11:39:49

对我来说,这里所说的所有事情 https://stackoverflow.com/a/6395750/939501 都是正确的,但仍然如此抛出错误,原因是我创建了一个名为 ABCView 的视图类,然后删除了它,然后我添加了一个视图控制器作为 ABCViewController ,所以不知何故它在新视图控制器中引用了旧的 ABCView ,我不得不删除 ABCViewController 并添加一个新的不同的名称解决了我的问题。

谢谢

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.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文