在我的应用程序中,我使用了 presentModalViewController,在下一个控制器中,我使用了 UIScrollView,也使用了关闭 presentModalViewController UITapGestureRecognizer
我的代码就像,
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedOnView:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
tapGesture.delegate = self;
[self.fullScreenImageView addGestureRecognizer:tapGesture];
-(void)tappedOnView:(UIGestureRecognizer*)gestureRecognizer {
[self dismissModalViewControllerAnimated:YES];}
但这给了我一个错误
attempt to dismiss modal view controller whose view does not currently appear. self = <UITabBarController: 0xabb0610> modalViewController = <FullScreenViewController: 0xab5c440>
所以我替换了调用方式
if ([self respondsToSelector:@selector(presentingViewController)]) {
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}
但是代码不起作用。我不能解雇我的 presentModalViewController。没有滚动视图它的工作。上面的代码有什么问题?