2014-09-13 80 views
0

我在使用附加的長按手勢來獲取使用以下代碼的模式視圖時收到此錯誤:警告:嘗試呈現其視圖不在窗口層次結構中的***

// 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上長按按鈕創建一個細分。

任何想法爲什麼會發生這種情況?

+0

嘗試分配[super viewDidLoad];在viewDidLoad方法中添加手勢之前 – Coder404 2014-09-13 20:38:45

+0

沒有幫助..:/ – Prateek 2014-09-13 20:46:29

回答

1

我已經通過改變代碼來處理的手勢,如下修正了這個:

// 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]; 
    } 

} 

這似乎是解決這個問題。

相關問題