在 xCode 中,我收到错误“已加载笔尖,但未设置视图出口”?
我知道有多个问题询问同一件事,但他们的解决方案都不适合我。
我制作了一个自定义的viewController类(Home),并单独制作了一个.xib。 (实际上,我将有 2 个笔尖——一个用于加载 ipad 版本,另一个用于 iphone)。
当我尝试实例化家庭类的实例时,我收到了问题中提到的错误。
在 xib 文件中,我所做的只是将一个视图控制器对象从库拖到屏幕上,它会自动在文件所有者和第一响应者下方添加一个视图控制器图标。然后我进入 viewController 对象的检查器并将类从 viewController 更改为 Home。
我从解决方案中发现的下一步是连接检查器的视图出口。我不完全确定应该将其连接到什么。我找到的解决方案说将其连接到视图图标,但同样,我看到的只是文件所有者、第一响应者和 vc 对象。它没有连接到它们
这是我在应用程序委托中放入的内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Home *homePage = [[Home alloc] initWithNibName:@"HomeIpad" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homePage];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
I know there are multiple questions asking the same thing, but none of their solutions worked for me.
I made a custom viewController class (Home), and I made a .xib separately. (Effectively, I'll have 2 nibs -- one for the ipad version to load, and another for the iphone).
When I try to instantiate an instance of the home class, I got the error I mentioned in the question.
In the xib file, all I did was drag a viewcontroller object from the library to the screen, and it automatically added a viewcontroller icon below the file's owner and the first responder. I then went into the inspector of the viewController object and changed the class from viewController to Home.
The next step that I've discerned from the solutions is to connect the view outlet from the inspector. I'm not entirely sure what I'm supposed to be connecting it to. The solutions I've found say to connect it to the view icon, but again, all I see is files owner, first responder, and the vc object. It connects to none of them
Here is what I put in the app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Home *homePage = [[Home alloc] initWithNibName:@"HomeIpad" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homePage];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是对于文件的所有者,我没有将类设置为 Home
the problem was that for the file's owner, i hadn't set the class to Home
您不需要拖动视图控制器。只需拖动一个 UIView 并将文件的所有者视图连接到此 UIView 即可。
You dont need to drag the view controller. Just drag a UIView instead and connect the File's owner View to this UIView.
我建议您使用 Xcode 的 File->New->New File->Cocoa Touch->UIViewController 子类->使用 XIB 作为用户界面来创建 Nib(执行此操作两次,一次使用 Targeted for iPad已检查)。我发现这是创建和连接 XIB 最可靠的方法。
即使您想要同一控制器有两个 XIB,也可以使用任何临时名称(例如 tempvc)创建第二个 VC 子类。现在,将 tempvc.xib 重命名为 HomeIpad.xib。右键单击 HomeIpad.xib 并选择“打开方式”->“源代码”。在源代码中,搜索 tempvc 并将其替换为所有出现的控制器的名称。现在一切都应该好了。
I would suggest you to create the Nib using Xcode's File->New->New File->Cocoa Touch->UIViewController subclass->with XIB for user interface (do this twice, once with Targeted for iPad checked). I find this to be the most reliable way of creating and hooking up XIBs.
Even if you want two XIBs for the same controller, create the 2nd VC subclass using any temporary name (say tempvc). Now, rename tempvc.xib to HomeIpad.xib. Right Click on HomeIpad.xib and select Open As->Source code. In the source, search for tempvc and replace it with the name of your controller for all occurrences. Everything should be good now.