ios - 在 IOS 中工作的返回屏幕按钮

标签 ios objective-c

我有一个 View Controller ,上面有一个 map View 。 map View 上方有一个后退按钮,单击该按钮后应返回 View Controller 。但是当我按下后退按钮时,它不会进入后退屏幕。我的代码在 View didLoad 中是这样的,

 UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(10, 20, 30,30)];
[backButton setImage:[UIImage imageNamed:@"row.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popVC) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backButton];
- (void) popVC{
HomeViewController *presales = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self.navigationController pushViewController:presales animated:YES];

按钮是这样的, enter image description here

最佳答案

移回HomeViewController

如果您使用 pushViewController 来显示当前 View Controller 。您必须使用 popViewControllerAnimated 而不是 pushViewController。尝试用下面我的代码替换你的 popVC

- (void) popVC{
    [self.navigationController popViewControllerAnimated:YES];
}

如果您使用 presentViewController 来显示当前 View Controller 。您必须使用 dismissViewControllerAnimated 而不是 pushViewController。尝试用下面我的代码替换你的 popVC

- (void) popVC{
    [self dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 在 IOS 中工作的返回屏幕按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47173819/

相关文章:

ios - 将 .3ds/.obj/.max/etc 文件导入 Cocos3D 项目

ios - 解析自动登录--隐藏登录界面

ios - 快速从单独的 nib 文件加载 UIViewController?

iphone - 转身从类方法分配属性

ios - 必须触摸 fbloginview 两次才能工作

ios - 由于未捕获的异常而终止应用程序 'NSUnknownKeyException' - IOS

ios - 移动基板 : Undefined symbols for architecture armv7: "_main"

ios - 从 Objective C 中的父类(super class)初始化子类

objective-c - 建议 : Best way to sync sqllite ios to web

iPhone - 与多个 UIGestureRecognizer 冲突