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];
}
そして、次のように直接呼び出したいscheduledTimerWithTimeInterval
:
[NSTimer scheduledTimerWithTimeInterval:0.001 target:TestAlert selector:@selector( showErrorAlert:) userInfo:error repeats:NO];
もちろん文法ミスはあります。
私showErrorAlert
はメソッドに置くことができることを知っています:
- (void)showError:(NSTimer *)timer
{
//NSLog(@"show error %@", error);
[TestAlert showErrorAlert:(NSString *)[timer userInfo]];
}
それで
[NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(showError:) userInfo:error1 repeats:NO];
ただし、 r メソッドshowErrorAlert
からのエラー メッセージが解放されているため、 を呼び出すとクラッシュします。showErro
直接電話showErrorAlert
してもいいですか? できない場合、エラー メッセージのリリースを回避するにはどうすればよいですか?