tags:

views:

68

answers:

1

Hello All,

I do like:

...

**//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).I touch the but until showing the uialertview, then i go to click the cancle button of the uialertview ,but the uialertview cann't close.

2).If i turn "[timer invalidate];" into “//[timer invalidate];”,and do like 1). the uialertview can close.

Why?

If you know why,please tell me. Thank you.

A: 

You're not releasing the alert view.

    UIAlertView *alert = [ [ UIAlertView alloc ] initWithTitle:@"hello" message:@"alerts" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil ];
    [alert show];
    [alert release]; // <-- important
Kalle