我試圖在按下按鈕時調用併發出警報。我使用這個:使用UIAlertView檢測按鈕單擊
-(IBAction)Add {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"add button pressed"
message:@"Add to record"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil ];
[alert show];
[alert release];
}
好的,這裏沒問題,兩個按鈕上來,確定並取消。現在我想檢測哪個按鈕被按下我使用:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
//just to show its working, i call another alert view
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"OK WORKIng well"
message:@"no error" delegate:nil
cancelButtonTitle:@"IWORKS"
otherButtonTitles:@"NO PRB", nil];
[alert show];
[alert release];
}
else
{
NSLog(@"cancel");
}
}
現在,這是問題。我無法檢測到哪個按鈕被按下;第二個alertview不顯示。我已經通過代碼檢查了幾次,似乎沒有任何問題。沒有錯誤/警告。
在另一個提醒後直接顯示提醒可能不是一個好主意 - 只是一個提示。 – vakio 2010-08-16 08:56:22