當我按下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。 謝謝
什麼不正確?你的代碼是否通過了'if'測試? – Larme
當您在clickedButtonAtIndex中放置斷點並進行調試時會發生什麼?它是否繞過了if語句?還是它叫performSegue? Segue是否正確命名,並且它們是否直接連接到TriageViewController?想要張貼故事板那部分的照片嗎? – valheru
嘿傢伙,塞格沒有工作。我意識到我忘了將代理設置爲'self',就像@Miron回答的那樣。謝謝 –