0

我为警报创建了一个类级别的方法:

@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];

但是showErrorAlert调用时会导致崩溃,因为showError 方法的错误信息已被释放。

我可以直接打电话吗showErrorAlert,如果我不能,我应该如何避免错误消息的发布?

4

2 回答 2

2

只需[TestAlert class]用作目标而不是TestAlert.

于 2012-06-15T04:04:45.267 回答
0

试试这个怎么样。您可以在此处找到提供的所有类型的 performSelector: 方法:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html

  • 执行选择器:
  • performSelector:withObject:
  • performSelector:withObject:withObject: – performSelector:withObject:afterDelay:
  • performSelector:withObject:afterDelay:inModes:
  • performSelectorOnMainThread:withObject:waitUntilDone:
  • performSelectorOnMainThread:withObject:waitUntilDone:modes:
  • performSelector:onThread:withObject:waitUntilDone:
  • performSelector:onThread:withObject:waitUntilDone:modes:
  • performSelectorInBackground:withObject:
于 2012-06-15T06:26:16.740 回答