几个UINavigation控制器(每个选项卡一个),作为我的应用程序委托的插座吗? [英] Several UINavigation controllers, one for each tab, as an outlets from my app delegate?

查看:46
本文介绍了几个UINavigation控制器(每个选项卡一个),作为我的应用程序委托的插座吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更多是关于一个问题和我的实现的讨论,这似乎是引起问题的原因.

This is more of a discussion on an issue and my implementation, which seems to be causing issues.

我的应用程序具有一个标签栏和导航控制器.在每个选项卡中,您都可以进入视图,并且选项卡栏将被隐藏,直到您从子视图中单击回来为止.

My app has a tab bar and navigation controllers. Within each tab you can go into views, and the tab bar will be hidden until you click back from your sub view.

我的每个选项卡上都有一个导航控制器,它们在我的应用程序委托中声明为插座,并且还具有 @class tab1navcontroller

I have a navigation controller for each on my tabs, these are declared as outlets in my app delegate and also have @class tab1navcontroller

典型的用途是

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] 
       delegate];
[delegate.tab1NavController pushViewController:nextController animated:YES];

过去我对此并没有很多问题,我相信我是从当时正在阅读的书中复制这种方法的.

I haven't had many problems with this in the past and I believe I copied the approach from a book I was reading at the time.

但是,几个月前,我与一位同事进行了讨论,他说我的应用程序应该只有一个导航控制器.

However, I had a discussion with a colleuge some months ago who said I should only have one navigation controller for my app.

当时我确实尝试替换了代码(如上所示)并使用了 self.navigationcontroller ,但这引起了问题,我不记得它们是什么,但是我放弃了这些修复程序

At the time I did try and replace the code (shown above) and use self.navigationcontroller instead, but this caused problems, I can't remember what they were, but I discarded those fixes.

今天,当按下视图并快速向后轻按时,发生了一个错误.我还使用僵尸事件探查器运行了该应用程序,这表明上面的代码是问题所在.

Today an error has occurred, when the view is pushed and back tapped quickly. I also ran the app with the zombie profiler and this indicated the code above was the problem.

我相信上面的代码可能会导致泄漏.

I believe the code above could be causing leaks.

我只是不知道哪种方法最好,从这里去哪里?

I just don't know what approach is best and where to go from here ?

推荐答案

正如@Dima在评论中所说,您的同事是错误的.在我的应用程序中,我有一个tabbarController作为窗口rootViewController.您可以在属性或其viewController数组或单个导航控制器中公开它.您不能在多个选项卡中重复使用导航控制器-每个选项卡一个或混合使用.也就是说,在我的tabbarController中,我有4个naviationControllers和一个普通的UIViewController子类.

As @Dima said in the comment, your colleague was wrong. In my app I have one tabbarController as the window rootViewController. You can either expose it in a property or its viewController array or the individual navigation controllers. You CANNOT reuse a navigation controller in multiple tabs - its one for each, or a mix. That is, in my tabbarController, I have 4 naviationControllers and one plain UIViewController subclass.

标签栏控制器保留其所有viewController,而NavigationControllers保留其所有viewController.就是说,如果您对弹出的viewController具有分配"类型引用,就会遇到问题.

The tab bar controller retains the all its viewControllers, and the navigationControllers retain all their viewControllers. That said, you get into problems if you have a 'assign' type reference to a viewController that gets popped.

这篇关于几个UINavigation控制器(每个选项卡一个),作为我的应用程序委托的插座吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆