0

當我按下AlertView上的手動輸入和掃描標籤按鈕時,我想要執行一個繼續。iOS - 從警報視圖繼續調用

@implementation triageViewController 
- (IBAction)addNew:(id)sender { 

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add A New Entry" 
               message:@"Choose a way to add a new entry." 
               delegate:nil 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"Manual Entry", @"Scan Tag", nil]; 
    [alert show]; 
} 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex != alertView.firstOtherButtonIndex) { 
    [self performSegueWithIdentifier:@"manual" sender: self]; 
} 
    if (buttonIndex != alertView.cancelButtonIndex) { 
    [self performSegueWithIdentifier:@"scan" sender: self]; 
    } 
} 

(我知道這很可能使取消按鈕大跳賽格瑞的權利,但我更關心的是使其工作)

我有兩個塞格斯在我的故事板,從去UITabViewController到兩個不同的UIViewControllers。這些都沒有被稱爲,所以當我點擊它們。我嘗試使用push和modal segues,但都沒有工作。

我也試過if/else語句,像這樣:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
if (buttonIndex == 0) { 
    [self performSegueWithIdentifier:@"manual" sender: self]; 

} 
if (buttonIndex == 1) { 
    [self performSegueWithIdentifier:@"scan" sender: self]; 
} 
} 

但這不是工作要麼。

有人可以幫我弄清楚出了什麼問題嗎?再次如果我不清楚,我想從位於UITabBarController上的UIAlertView彈出窗口執行segue到兩個單獨的UIViewControllers。 謝謝

+0

什麼不正確?你的代碼是否通過了'if'測試? – Larme

+0

當您在clickedButtonAtIndex中放置斷點並進行調試時會發生什麼?它是否繞過了if語句?還是它叫performSegue? Segue是否正確命名,並且它們是否直接連接到TriageViewController?想要張貼故事板那部分的照片嗎? – valheru

+0

嘿傢伙,塞格沒有工作。我意識到我忘了將代理設置爲'self',就像@Miron回答的那樣。謝謝 –

回答

1

它看起來像你的UIAlertViewdelegatenil所以你的功能永遠不會被調用。將其設置爲self,然後在您的視圖控制器的頭部中確保您正在實施UIAlertViewDelegate協議。

+0

不知道爲什麼我沒有注意到,謝謝你救了我頭痛。 –