Iphone UINavigationBar.items访问器不';t返回当前UINavigationItem

Iphone UINavigationBar.items访问器不';t返回当前UINavigationItem,iphone,cocoa-touch,uinavigationbar,Iphone,Cocoa Touch,Uinavigationbar,在我的UINavigationBar:didPopItem:函数中,导航栏的\u itemStack中有n个项目,如调试器中所示,但.items访问器函数返回一个包含n-1个项目的数组,缺少当前导航项目,这就是我要检查的内容backItem返回n-2项而不是n-1项,以此类推。didPopItem项是“n+1”项,因此也没有帮助 如何访问当前的UINavigationItem 我正在使用iPhone 3.0 SDK。回调发生在项目被删除后,因此当前导航项目可能不是您所期望的 请尝试将代码放入委托

在我的
UINavigationBar:didPopItem:
函数中,导航栏的
\u itemStack
中有n个项目,如调试器中所示,但
.items
访问器函数返回一个包含n-1个项目的数组,缺少当前导航项目,这就是我要检查的内容
backItem
返回n-2项而不是n-1项,以此类推。
didPopItem
项是“n+1”项,因此也没有帮助

如何访问当前的UINavigationItem

我正在使用iPhone 3.0 SDK。

回调发生在项目被删除后,因此当前导航项目可能不是您所期望的

请尝试将代码放入委托方法中,这将在删除项之前被调用

i、 e.您的堆栈上有3个项目,A、B和C

删除C时,会发生以下情况:

  • shouldPopItem与项一起调用 作为数组[A,B,C]
  • C被移除
  • 调用didPopItem时,项数组为[A,B]
  • 如果要保留要删除的项,请在shouldPopItem方法中存储对该项的引用,以便调用didPopItem方法时该项仍然存在

    希望有帮助

    S

    似乎“items”属性将在返回RunLoop后进行调整。 所以试着这样做

    -(void)XXX:(UINavigationBar*)nBar {
        UINavigationItem *cItem = [nBar.items objectAtIndex:(nBar.items.count - 1)];
    }
    
    -(void)navigationBar:(UINavigationBar *)nBar didPopItem:(UINavigationItem *)item {
        [ self performSelector:@selector(XXX) withObject:nBar afterDelay:0 ];
    }
    

    但我的问题是,items只包含[A],而不包含[A,B]
    didPopItem
    是C。B是我想看的,但我看不见。但是我可以做的是在
    shouldPopItem
    中的注释B,这样我就可以在
    didPopItem
    中检查它。我正在决定是否应该隐藏工具栏。哦,真奇怪。topItem包含什么?嗯
    topItem
    包含一个。
    backItem
    包含零,就好像堆栈短了一个一样。正如我所说,调试器显示[A,B],但是
    。items
    只显示[A]。但更奇怪的是,仅仅添加一个返回
    YES
    shouldPopItem
    委托就破坏了应用程序。导航栏将停止弹出内容视图。酒吧会弹出,但视图不会弹出。(与编写应用程序相比,我花更多的时间来处理类似的Cocoa怪癖。
    didPopItem
    在横向模式下甚至不会被调用,但是,
    didPushItem
    会被调用。--另一个问题。我应该去SDK 3.1吗?)尝试3.1可能是个好主意。您有一些示例代码吗?-(BOOL)导航栏:(UINavigationBar*)nBar shouldPopItem:(UINavigationItem*)项{theItem=nBar.topItem;返回YES;}-(void)导航栏:(UINavigationBar*)nBar didPopItem:(UINavigationItem*)项{BOOL hideBar=true;//UINavigationItem*cItem=[nBar.items对象索引:(nBar.items.count-1);//不起作用UINavigationItem*cItem=theItem;如果([cItem.title compare:@“@Home”]==sensorderedName)hideBar=false;如果([cItem.title compare:@“components”]==sensorderedName)hideBar=false;[self-SetToolbar hidden:hideBar animated:true];]非常聪明。一些很少有人会想到的东西。谢谢你的回答。我会尝试一下。这就是正在发生的事情!如果有人不喜欢按
    性能选择器的方式(像我一样),他们可以使用(UINavigationControllerDelegate)。