popViewController从后退按钮动画

时间:2010-05-16 03:12:20

标签: iphone popviewcontroller

如何从后退按钮弹出视图,我从前一个视图控制器传递了以下代码。感谢

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
         initWithTitle:@"Back"
         style:UIBarButtonItemStyleBordered
         target:nil action:nil];

1 个答案:

答案 0 :(得分:3)

无需手动添加后退按钮。

但是,如果您真的需要该自定义按钮来弹出视图控制器,您可以制作自定义消息。

-(void)popViewControllerWithAnimation {
  [self.navigationController popViewControllerAnimated:YES];
}
...
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
     initWithTitle:@"Back"
     style:UIBarButtonItemStyleBordered
     target:self action:@selector(popViewControllerWithAnimation)];

或者创建一个NSInvocation。

NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
      [self.navigationController methodSignatureForSelector:@selector(popViewControllerAnimated:)]];
// watch out for memory management issues: you may need to -retain invoc.
[invoc setTarget:self.navigationController];
[invoc setSelector:@selector(popViewControllerAnimated:)];
BOOL yes = YES;
[invoc setArgument:&yes atIndex:2];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
     initWithTitle:@"Back"
     style:UIBarButtonItemStyleBordered
     target:invoc action:@selector(invoke)];