我的應用程序需要警惕味精,如果是按下按鈕然後一個更加警覺味精,然後我不得不叫method.This是我的代碼:UIAlert查看換是/否條件
-(IBAction)resetPressed:(id)sender
{
NSString *title= [NSString stringWithFormat:@"Warning"];
NSString *message = [NSString stringWithFormat:@"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:@"No"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:@"Yes",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alertView.tag ==1)
{
NSString *title= [NSString stringWithFormat:@"Warning"];
NSString *message = [NSString stringWithFormat:@"Are you sure you want to Reset"];
NSString *ok = [NSString stringWithFormat:@"No"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:ok otherButtonTitles:@"Yes",nil];
alert.tag =2;
[alert show];
[alert release];
}
else if(alertView.tag ==2)
{
[self resetArray];
}
}
感謝。
什麼問題? – kennytm 2010-07-03 06:17:00
感謝Kenny。在這段代碼中,alert.tag == 1條件沒有得到滿足,所以msg沒有被打印。只有當2 msg是yes時,方法纔會被調用。如果你可以解決這個問題,那麼請。 謝謝 – 1988 2010-07-03 06:34:42
同一位用戶可能有[UIAlert View-for yes/no condition](http://stackoverflow.com/questions/3165070/uialert-view-for-yes-no-condition)的副本。請改變問題而不是重新發布。 – vikingosegundo 2011-11-08 22:45:18