ios - 后退按钮没有反应?

标签 ios objective-c ios6 uinavigationcontroller uibutton

我是 iOS 开发的新手,目前坚持创建后退按钮。我已经放了 popViewControllerAnimated 点击按钮的方法,我也在 Debug模式下测试它,后退按钮方法正在调用,但是 popViewControllerAnimated 不管用。

这是代码。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.height-100), 30, 80, 20)];
    [backButton setTitle:@"Back" forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(BackButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];

    //some piece of code...

}//end of viewDidLoad method


-(void)BackButtonClicked: (id)sender{  
    [self.navigationController popViewControllerAnimated:YES];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"testing" message:@"some message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"NO", nil];
    [alert show];

}

在点击返回按钮时,此警报会显示,但屏幕不会返回。

任何有关此问题的帮助都将不胜感激。

我通过在我以前的 viewController 中编写这段代码来调用这个 viewController
PlaceTranslatedDetailsViewController *secondViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"placeTranslatedDetail"];
[self presentViewController:secondViewController animated:YES completion:NULL];

然而,这个 viewController 和之前的 viewController 是通过编程设计的

最佳答案

如果您的 viewcontroller不是 rootviewcontroller对于 uinavigationcontroller比方法popViewControllerAnimated不会工作。所以你需要有一个uinavigationcontroller后面为了推送/弹出 viewcontroller .

因此,在您的情况下,您必须使用 [self dismissViewControllerAnimated:YES completion:nil];而不是 popViewController因为您以模态方式呈现了一个 View Controller 。

关于ios - 后退按钮没有反应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17675560/

相关文章:

ios - 什么样的变换会给我想要的结果图像?

ios - 无需越狱访问应用程序文件夹

objective-c - 如何在 AVPlayer 中播放 Youtube 视频?

objective-c - iOS 在 UITableViewCells 之间显示 UIDatePicker

ios - 内存警告-MapOverlay

ios - iOS中的GCDWeb服务器崩溃问题

javascript - 如何在 Apple Instruments 中启用 Javascript 语法检查

xcode - 无法打开此文档 "XXXXX.storyboard"。请使用较新版本的 Xcode

css - 如何防止在每个页面加载背景图片?

ios - UISearchbar 在 UIScrollView 中消失