I make a class level method for Alert:
@interface TestAlert
@end
+ (void)showErrorAlert:(NSTimer *)message
{
.......
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:messageIn delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
and I want to call it directly in scheduledTimerWithTimeInterval like:
[NSTimer scheduledTimerWithTimeInterval:0.001 target:TestAlert selector:@selector( showErrorAlert:) userInfo:error repeats:NO];
There have grammar error of course.
I know I can put showErrorAlert to a method:
- (void)showError:(NSTimer *)timer
{
//NSLog(@"show error %@", error);
[TestAlert showErrorAlert:(NSString *)[timer userInfo]];
}
Then
[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(showError:) userInfo:error1 repeats:NO];
But it will cause crash when showErrorAlert is called, because error message from showError method has been released.
Can i call showErrorAlert directly, If I can’t, how should I avoid error message’s release ?
Just use
[TestAlert class]as a target instead ofTestAlert.