如何从 UIViewController 获取 UIView 而不将控制器添加到视图层次结构并使其可见?
我想避免以编程方式布局视图。
我只想使用 NIB 文件来完成这样的工作。
问题是,据我所知,使 NIB 文件生效的唯一方法是通过控制器,如下所示:
ZBarReaderViewController* reader = [[ZBarReaderViewController alloc] init];
ScannerOverlayViewController *sovc =
[[ScannerOverlayViewController alloc] initWithNibName:@"ScannerOverlayView" bundle:nil];
reader.cameraOverlayView = sovc.view;
但这种方法效果不佳,因为单步执行调试器显示视图为 0x0 或 Nil。
现在这可能是因为控制器永远不会添加到/显示在视图层次结构上,我试图从中获取一个视图,以便将其回收为另一个控制器上的“覆盖视图”,该控制器允许我指定它。
对于如何在不以编程方式编写视图的情况下实现这一点有什么想法吗?
I want to avoid laying out a view programmatically.
I want to only use a NIB file to do such work.
The problem is that the only way that I know of bringing a NIB file to life is via a controller like so:
ZBarReaderViewController* reader = [[ZBarReaderViewController alloc] init];
ScannerOverlayViewController *sovc =
[[ScannerOverlayViewController alloc] initWithNibName:@"ScannerOverlayView" bundle:nil];
reader.cameraOverlayView = sovc.view;
But this approach doesn't work out so well because stepping through the debugger shows that the views is 0x0 or Nil.
Now this may be because the controller is never added-to/displayed-on the view hierarchy and I'm trying to get a view out of it in order to recycle it as an "overlay view" on another controller that allows me to specify it.
Any thoughts on how this can be accomplished without writing the View programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从 XIB 文件加载视图:
You can load view from XIB file: