开发者

popViewControllerAnimated from back button

开发者 https://www.devze.com 2022-12-30 04:52 出处:网络
How can I popview from back button pressed, i passed the below code from previous view controller. Thanks

How can I popview from back button pressed, i passed the below code from previous view controller. Thanks

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
         initWithTitle:@"Back"
      开发者_开发百科   style:UIBarButtonItemStyleBordered
         target:nil action:nil];


There's no need to manually add a back button.

But if you really need that custom button to pop the view controller, you could make a custom message.

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

Or create an 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)];
0

精彩评论

暂无评论...
验证码 换一张
取 消