我想显示一个大约 2 秒的临时警报,让用户有机会取消操作。如果用户单击取消按钮,则不会调用后续方法。但是,如果用户没有按取消,则将调用后续方法。有人对如何使这项工作有任何想法吗?
我有一个看起来像这样的设置:
-(void) buttonPress {
//alert with message and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"2 seconds to cancel"
message:@"Push Cancel to stop" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:nil, nil];
alert.tag = 1;
[alert show];
return;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0 && alertView.tag == 1) {
//action cancelled
}
else {
//action not cancelled
}
}