popViewController由后退按钮动画

发布于 2024-09-01 21:05:39 字数 240 浏览 11 评论 0原文

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

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

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];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木槿暧夏七纪年 2024-09-08 21:05:39

无需手动添加后退按钮。

但如果您确实需要自定义按钮来弹出视图控制器,则可以创建自定义消息。

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

或者创建一个 NSInspiration。

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)];

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)];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文