我喜欢:
**//some methods of myButton inheried from UIButton**
-(void)timerFireMethod:(NSTimer*)theTimer
{
UIAlertView *alert = [ [ UIAlertView alloc ] initWithTitle:@"hello" message:@"alerts" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil ];
[alert show];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[timer invalidate];
}
1)我触摸但是直到显示uialertview,然后我去点击uialertview的取消按钮,但是uialertview没有关闭。
2)如果我将[timer invalidate];
变为//[timer invalidate];
并按照我在上面的代码中所做的那样,uialertview可以关闭。
为什么?
答案 0 :(得分:0)
您没有发布提醒视图。
UIAlertView *alert = [ [ UIAlertView alloc ] initWithTitle:@"hello" message:@"alerts" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil ];
[alert show];
[alert release]; // <-- important