我在 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/