在我的UIAlertView
我有两个按钮是,否。如果我按Yes
做某事,如果我按 No
取消UIAlertView
所以我可以做到这一点,但我的问题是,如果我不按任何按钮,它就会计数 10 seconds
并做点什么?
有什么方法吗?
最佳答案
检查一下这个方法是否有效。将NSTimer类的定时器作为全局变量。
when you click on alert button at that time you must be
invalidate
the timer.
在.h文件中这样声明
NSTimer *timer;
UIAlertView *myalert;
myalert = [[UIAlertView alloc] initWithTitle:@"alert"message:@"hi"
delegate:self cancelButtonTitle:@"no"
otherButtonTitles:@"yes", nil];
[myalert show];
timer= [NSTimer scheduledTimerWithTimeInterval:4.0
target:self selector:@selector(test)
userInfo:nil
repeats:NO];
-(void)test{
[myalert dismissWithClickedButtonIndex:-1 animated:YES];
//do somthing
}
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
if(timer!=nil){
[timer invalidate];
timer=nil;
}
}
关于ios - UIAlertView 当没有按钮按下时计数 10 秒并执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16746817/