Ios 后退按钮没有响应?

Ios 后退按钮没有响应?,ios,objective-c,ios6,uinavigationcontroller,uibutton,Ios,Objective C,Ios6,Uinavigationcontroller,Uibutton,我是iOS开发的新手,目前正在创建后退按钮。我已经将popViewControllerAnimated方法放置在点击按钮上,并且在调试模式下对其进行测试,返回按钮方法正在调用,但popViewControllerAnimated不起作用 这是代码 - (void)viewDidLoad { [super viewDidLoad]; UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake((self.vi

我是iOS开发的新手,目前正在创建后退按钮。我已经将popViewControllerAnimated方法放置在点击按钮上,并且在调试模式下对其进行测试,返回按钮方法正在调用,但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
不是
uinavigationcontroller
rootviewcontroller
,则此viewController和以前的viewController是以编程方式设计的,而
popViewControllerAnimated
方法将不起作用。因此,您需要在后面放置一个
uinavigationcontroller
,以便推/弹出
viewcontroller


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

如果
viewcontroller
不是
uinavigationcontroller
rootviewcontroller
,则方法
popViewControllerAnimated
将不起作用。因此,您需要在后面放置一个
uinavigationcontroller
,以便推/弹出
viewcontroller

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

使用以下代码:

 [self dismissViewControllerAnimated:YES completion:NULL]
使用此代码:

 [self dismissViewControllerAnimated:YES completion:NULL]

您没有将视图控制器显示为导航堆栈的一部分,因此使用
popViewControlleranimated:
将不起作用

你需要使用

[self dismissViewControllerAnimated:YES completion:NULL];

相反。

您没有将视图控制器显示为导航堆栈的一部分,因此使用
popViewControlleranimated:
将不起作用

你需要使用

[self dismissViewControllerAnimated:YES completion:NULL];
相反。

推送(通过
pushViewController
或情节提要推送序列)需要调用
popViewController

呈现视图(通过
presentVewController
或情节提要模式序列)需要调用
dismissViewController

推送(通过
pushViewController
或情节提要推送序列)需要调用
popViewController


呈现视图(通过
presentVewController
或故事板模式序列)需要调用
dismissViewController

您的视图控制器按下了什么?它是如何加载和呈现的?编写呈现你的视图控制器的代码请现在回顾一下,我对问题的内容做了一些更改你的视图控制器推动了什么?它是如何加载和呈现的?编写呈现你的viewcontrollerplease review的代码现在,我对我的问题的内容做了一些更改当前屏幕在点击后退按钮时向下滑动,是否可以在点击时将其滑动到右侧?苹果建议保持屏幕进入和离开的相同路线。如果它从顶部滑入,则应关闭到顶部。你可以采取不同的方式,但为了达到最佳效果,请保持屏幕在点击后退按钮时向下滑动,是否可以在点击时将其滑动到右侧?苹果建议保持屏幕进出的相同路线。如果它从顶部滑入,则应关闭到顶部。你可以用不同的方式来做,但为了达到最好的效果,还是保持原样。这应该是公认的答案+谢谢你解释这个问题。@Amar谢谢,没关系,我只希望他能读到我在这里解释的内容。这应该是公认的答案+谢谢你解释这个问题。@Amar谢谢,没关系,我只希望他能读到我在这里解释的内容。