警告:尝试显示其视图不在窗口层次结构中的*** [英] Warning: Attempt to present *** whose view is not in the window hierarchy
本文介绍了警告:尝试显示其视图不在窗口层次结构中的***的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用附加的长按手势使用以下代码获取要显示的模态视图时,出现此错误:
I'm receiving this error when I am using an attached long press gesture to get a modal view to come up using the following code:
// Long press to go to settings for one
- (void)longPressOne:(UILongPressGestureRecognizer*)gesture {
[self performSegueWithIdentifier:@"buttonOne" sender:self];
}
// Long press to go to settings for two
- (void)longPressTwo:(UILongPressGestureRecognizer*)gesture {
[self performSegueWithIdentifier:@"buttonTwo" sender:self];
}
- (void)viewDidLoad {
// Add gesture to buttonOne
UILongPressGestureRecognizer *longPressOne = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressOne:)];
[self.buttonOne addGestureRecognizer:longPressOne];
// Add gesture to buttonTwo
UILongPressGestureRecognizer *longPressTwo = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressTwo:)];
[self.buttonTwo addGestureRecognizer:longPressTwo];
}
模态选择在视图板上的情节提要中被捆绑到目标视图.我知道在情节提要板上有多个segue时有关于此问题的报告,但是我只有一个,因为我无法通过长按Storyboard上的按钮来创建情节.
The modal segue is hitched up on the storyboard from the viewcontroller to the destination view. I know there are reports of this problem when there are multiple segues on the storyboard, but I just have the one as I can't create a segue from the button for a long press on Storyboard.
知道为什么会这样吗?
推荐答案
我已通过更改处理手势的代码来解决此问题,如下所示:
I have fixed this by altering the code for handling the gestures, as below:
// Long press to go to settings for one
- (void)longPressOne:(UILongPressGestureRecognizer*)gesture {
if (gesture.state == UIGestureRecognizerStateBegan)
{
[self performSegueWithIdentifier:@"buttonOne" sender:self];
}
}
// Long press to go to settings for two
- (void)longPressTwo:(UILongPressGestureRecognizer*)gesture {
if (gesture.state == UIGestureRecognizerStateBegan)
{
[self performSegueWithIdentifier:@"buttonTwo" sender:self];
}
}
这似乎可以解决问题.
这篇关于警告:尝试显示其视图不在窗口层次结构中的***的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文