-(void)alertOKCancelAction
{
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Return Home" message:@"Are
you sure you want to return to the menu?" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
-(void)alertConnectionLost
{
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Lost"
message:@"The connection to the other device has been lost" delegate:self
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
}
else
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
}
如上所示,我有2个提醒。但他们都用相同的方法来处理按键。如何判断哪个警报当前处于活动状态并根据哪个警报响应而以不同方式响应按键?
答案 0 :(得分:2)
分别使用:[alert setTag:1];
和[alert setTag:2];
然后你可以这样做:
if([actionSheet tag] == 1){
//do thing for first alert view
}
else if([actionSheet tag] == 2){
//do something for second alert view
}