是否建议在 UINavigationController 视图和模态视图中使用相同的 xib?
我的 iPhone 应用程序中有一个视图(和相应的视图控制器),允许用户编辑应用程序的设置。该视图可通过菜单(表格视图)访问。我在 UIViewController 子类中使用 PushViewController 来显示它。当我执行此操作时,它会按我的预期显示 - 导航栏出现在 xib 顶部,并且我在 xib 中留下的空白空间已被占用。
我有时还使用presentModalViewController 将设置视图显示为模式视图。当我这样做时,xib 的顶部从导航栏的底部开始,而不是在其下方。
文档确实说presentModalViewController将调整视图大小以适应,所以我可以看到这是预期的行为。然而,对我来说,这不是理想的行为。
我可以通过将设置视图控制器设置为不显示导航栏来解决这个问题,但是视图顶部有一个奇怪的空白区域。
理想情况下,我想在这两种情况下使用相同的 xib。但是,也许这不是最佳实践?你们通常如何重用 xib?
我在想,如果视图控制器处于模态模式,也许我可以将所有控制器向上移动,但我想要更好的东西(如果有的话)。
I have a view (and corresponding view controller) in my iPhone app that allows the user to edit settings for the application. This view is accessible via a menu (a table view). I use pushViewController in my UIViewController subclass to get it shown. When I do this, it appears as I expect - the nav bar appears on top of the xib, and the empty space I left up there in the xib is occupied.
I also sometimes show that settings view as a modal view using presentModalViewController. When I do this, the top of the xib starts at the bottom of the nav bar instead of underneath it.
The documentation does say that presentModalViewController will resize the view to fit, so I could see this being expected behavior. However, for me, it isn't desired behavior.
I can kind of work around it by setting the settings view controller to not show the nav bar, but then there's a weird empty space at the top of the view.
Ideally, I'd like to use the same xib in both of these situations. However, maybe that's not a best practice? How do you guys usually reuse a xib?
I was thinking that maybe I could have the view controller shift all of the controllers up if it's in modal mode, but I'd like something better, if it's available.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 UIView 都有一个 autoresizingMask 属性。通过配置(可以在 Interface Builder 中完成),您应该能够重用该视图,并在导航栏不应该出现时自动调整其大小以占据整个屏幕。
苹果的文档在这里:
http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW10
Each UIView has an autoresizingMask property. By configuring that (can be done in Interface Builder), you should be able to reuse the view and have it automatically resize to take up the whole screen when the nav bar should not be there.
Apple's documentation is here:
http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW10