我有一个 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/