UITabbar 在应用程序启动时加载 2 个视图,而不仅仅是第一个视图
我有一个有 4 个按钮的 uitabbar。启动屏幕将按照应用程序启动时应有的方式加载。其中 2 个按钮视图在启动时不会加载(很好)。一个是网页视图,另一个是带有表格视图的导航控制器。最后一个视图在应用程序启动时加载。它是另一个带有表格视图的导航控制器。
我知道哪些正在加载,哪些没有,因为我将 nslog 添加到了所有顶级控制器上的 didload 函数中。
所以总体问题是,当我启动我的应用程序,然后旋转它,然后进入已经加载了表视图中标题的选项卡栏项目(这是一个网络视图)时,从未收到它应该旋转的备忘录,因此调整了大小。一旦你进入视图,如果你来回旋转,那么它就会正常工作。这只是最初的时间。
更新1: 问题是如何阻止选项卡栏另一个按钮上的第二个控制器在应用程序启动时加载。
更新2: 我在 didload 中完成了所有初始化工作,但我尝试添加以下代码,但它从未显示在日志中。我没有使用 IB,这一切都是通过编程完成的:
- (void)loadView
{
NSLog(@"Loading feedback");
}
更新 3: 我弄清楚是什么原因造成的。我确实有一个 xib 来容纳我的 tabbarcontroller。在该选项卡控制器中,我有一个导航控制器,然后我有一个视图控制器(我将类设置为我的反馈类),然后我有导航项和表视图。当我添加表视图时,它会触发控制器加载。只需删除它就会阻止它过早加载。然后为了修复它,我创建了一个用于反馈的 xib。所以我不喜欢让笔尖服务于单一目的,在这种情况下,它是为了在其中获取表格视图并使其成为分组样式。我可能会尝试手动添加表格视图,而不是使用表格视图控制器。
I have a uitabbar with 4 buttons. The start up screen loads as it should on the applications start. 2 of the buttons views don't load on start (good). 1 is a web view the other is a navigation controller with a table view. The last view does load on application start. It is another navigation controller with a table view.
I know which ones are loading and which are not because i added nslogs to the didload function on all top level controllers.
So the overall issue is that when i start my app, then rotate it, then go into the tabbar item that has already been loaded the header in the tableview which is a webview, never got the memo that it should have rotated, and therefore resized. Once your in the view if you rotate back and forth then it works as it should. Its just the initial time.
Update 1:
The question is how do I stop the 2nd controller that is on another button of the tab bar from loading on app start.
Update 2:
I do all my init stuff in didload but I tried adding the following code, but it never shows up in the log. I am not using IB, this is all done programmatically:
- (void)loadView
{
NSLog(@"Loading feedback");
}
Update 3:
I figured out whats causing this. I do have a xib that houses my tabbarcontroller. In that tabbarcontroller i have a navigation controller, then i have a view controller (I set the class to my feedback class), then i had the navigation item and a table view. When i add the tableview it triggers the controller to load. Simply removing that will stop it form loading early. Then to fix it, i created a xib for the feedback. So I dont like having nibs that server a single purpose, in this case its to get a table view in there and have it be a grouped style. I may try to just manually add the tableview instead of having a tableview controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在代码中更容易做到。选项卡栏控制器接受数组中的视图控制器,默认选项卡栏控制器是位于选项卡栏控制器的第一个索引处的控制器。
将所有与视图相关的任务放在 viewDidLoad 方法中,有时 loadView 会出现问题,这可能是因为您的 viewController 尝试加载一个新视图,该视图一次又一次地调用自身,因此最好将它们添加到 viewDidLoad 中。
Its much easier to do in code. The tab bar controller accepts the view controllers in the array and the default tab bar controller is the one which is at the first index of the tab bar controller.
Place all the view related task in viewDidLoad method sometimes loadView gies problem this may be because of your viewController trying to load a new view which calls itself again and again so better to add them to viewDidLoad.
过早加载的选项卡的视图控制器可能会在需要之前访问 self.view 属性。
如果很难找到访问点,请在
loadView
中添加断点,仅在需要时调用[super loadView]
进行虚拟重载(视图是从 NIB 加载的) )。断点堆栈跟踪将向您显示强制加载发生的位置。The view controller for the tab that loads prematurely probably accesses the
self.view
property before it is needed needed.If finding he access point is hard add a breakpoint to
loadView
, make a dummy overload only calling[super loadView]
if needed (The view is loaded from a NIB). The breakpoints stack trace will show you where you force the load to occur.