iphone - 无法关闭presentModalViewController

标签 iphone uiviewcontroller presentmodalviewcontroller

我在 iPhone 应用程序中有两个 View Controller 。

1.) FirstVC

2.) 第二个VC

在我的 FirstVC 中,我有一个按钮。通过点击该按钮,我在 presentModalViewController 中打开了 SecondVC。看下面的代码。

- (IBAction)buttonClicked:(id)sender
{
    SecondVC *secondVC = [SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil];
    [self.navigationController presentModalViewController:secondVC animated:YES];
}

现在转移到 SecondVC。在 SecondVC 上,我创建了导航栏以及“取消”按钮作为 leftBarButtonItem。我在取消按钮上设置了一个按钮单击事件。在这种方法中我想解雇 SecondVC。下面的方法是在 SecondVC 中。看下面的代码。

- (void)cancelButtonClicked
{
  [self dismissModalViewControllerAnimated:YES];
}

此代码不起作用。我不能通过这段代码解雇 SecondVC 。请提出其他技巧。

最佳答案

将按钮代码更改为此..

- (IBAction)buttonClicked:(id)sender
{
    SecondVC *secondVC = [SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil];
 [self presentViewController:secondVC animated:YES completion:NULL];

}

在取消按钮点击时

-(void)cancelButtonClicked {
 [self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];

}

关于iphone - 无法关闭presentModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138706/

相关文章:

Xcode:为什么我使用presentModalViewcontroller 收到SIGABRT 消息?

ios - 解除模态视图 Controller 时如何保持呈现 View Controller 的方向?

ios - ViewController 没有名为 "allValues"的成员

ios - 防止弹出框显示过度呈现的 View

objective-c - 当呈现的模态视图 Controller 被解除时,从主视图 Controller 知道吗?

ios - Dealloc 未调用更改选项卡

ios - 如何在 XCode 6 中查看 3.5 和 4 英寸的 StoryBoard View

iphone - iPhone的通用代码放在哪里,CLLocationManager

iphone - 如何在 objective-c 中声明常量

ios - 如何以编程方式对齐和移动两个标签?