Obj-C,带有选项卡控制器的导航控制器我是否错误地使用了它们? [英] Obj-C, Navigation Controller with Tab Controller am I using them incorrectly?

查看:21
本文介绍了Obj-C,带有选项卡控制器的导航控制器我是否错误地使用了它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我第一次设置我的应用程序时,我在使用单个导航控制器时遇到了一些问题.

我在每个标签项后面都有几个屏幕.我认为我遇到的问题是视图控制器在它们之间切换时会显示在错误的选项卡中.我并不担心在每个选项卡中保持最后一个使用的视图控制器处于打开状态,实际上我现在隐藏了选项卡栏以停止此操作.

所以目前我的每个选项卡都有导航控制器文件.我在主窗口的 IB 中分配了它们.

我像这样使用它们...

CategorySelTableViewController *nextController =[[[CategorySelTableViewController alloc] initWithNibName:@"CategorySelTableView" bundle:nil] autorelease];nextController.hidesBottomBarWhenPushed = YES;MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication]代表];[delegate.billsndepsNavController pushViewController:nextController 动画:YES];

但是,我有一些泄漏.

我无法释放我的委托,这会导致错误.

我的大学建议我应该只使用 self.navigationcontroller.

但这对我来说是一个很大的改变,我想在做出改变之前明确地知道我是否做错了?

解决方案

当一个视图控制器被压入栈时,它有两种方式来访问导航控制器:

  • 使用 self.navigationController.
  • 在委托中访问导航控制器 ivar:
    [UIApplication sharedApplication].delegate.navigationController

两者是等价的,但第一个较短,因此使用较多.从一种切换到另一种没有任何好处.进行额外输入的唯一原因是当您不在 pushed 视图控制器中时,例如:在独立 GUI 组件中使用的视图控制器,或不是视图控制器的对象.>

委托不应被释放,因为它在应用程序的整个生命周期中都存在.

When I first setup my app I had some issues getting a single navigation controller to work.

I have several screens behind each tab item. I think the problem I was getting was that view controllers would show within the wrong tabs, when switching between them. I'm not bothered about keeping the last view controller used open within each tab, in fact I hide the tab bar to stop this anway now.

So at the moment I have navigation controller files for each of my tabs. I have them assigned in IB, in the mainWindow.

And I use them like this...

CategorySelTableViewController *nextController = 
          [[[CategorySelTableViewController alloc] initWithNibName:
          @"CategorySelTableView" bundle:nil] autorelease];
nextController.hidesBottomBarWhenPushed = YES;

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] 
         delegate];

[delegate.billsndepsNavController pushViewController:nextController animated:YES];

However, I have some leaks.

I can't release my delegate, it causes an error.

My colleuge suggests that I should just be using self.navigationcontroller.

But this is a big change for me, I'd like to know definetively if I'm doing this wrong before I make the changes ?

解决方案

When a view controller is pushed into the stack, it has two ways to access the navigation controller:

  • Using self.navigationController.
  • Accessing the navigation controller ivar in the delegate:
    [UIApplication sharedApplication].delegate.navigationController

Both are equivalent but the first one is shorter, so it tends to be used more. There is no benefit from switching from one to the other. The only reason to do the extra typing is when you are not in a pushed view controller, eg: a view controller used in an independent GUI component, or an object that is not a view controller.

The delegate shouldn't be released because it exists during the whole life of the application.

这篇关于Obj-C,带有选项卡控制器的导航控制器我是否错误地使用了它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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