dismissViewControllerAnimated无法工作

8

我正在使用IOS6中的Storyboard。我试图返回到上一个视图控制器,但它没有起作用。

我在这里定制了我的返回按钮。

UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
btnBack.frame = CGRectMake(0, 0, 45,35);
[btnBack setTitle:@"Back" forState:UIControlStateNormal];
[btnBack.titleLabel setFont: [UIFont fontWithName:@"Courier" size:15]];
btnBack.layer.cornerRadius=5.0;
btnBack.layer.borderWidth=2.0;
[btnBack setBackgroundColor:[UIColor colorFbBlue]];
btnBack.layer.borderColor=[UIColor colorFbBlue].CGColor;
[btnBack setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnBack addTarget:self action:@selector(Click_On_Btn_Back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnBack];

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

 }

这是我从上一个视图控制器推出segue的方法。

if([segue.identifier isEqualToString:@"segueFbShare"]){
    FbShareViewController *fbVC=[segue destinationViewController];
    fbVC.imageUrl=self.product.ImageUrl;

}

你是将 viewController 作为模态视图呈现吗?你是否使用了 navigationController - Firo
不是模态的。只是一个推送。我正在使用navigationcontroller。 - user1302602
2个回答

19

使用 UINavigationController 时返回到上一个 UIViewController:

[self.navigationController popViewControllerAnimated:YES];

将这行代码放在你的Click_On_Btn_Back方法中


4

当使用导航控制器和 push 时,你需要通过以下方式移除视图:

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

此外,Click_On_Btn_Back 不符合 iOS 命名规范。应该使用更接近 驼峰命名法 的形式,例如:clickOnBtnBack


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接