2012-06-15 50 views
0
一類級別的方法

我爲警報一類級別的方法:呼叫scheduledTimerWithTimeInterval

@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被調用,因爲showErro R法的錯誤消息已經發布。

我可以直接撥打showErrorAlert,如果我不能,我該如何避免錯誤信息的發佈?

+0

如何使用'perform selector'方法? – Bazinga

+1

@Bazinga執行選擇器應該是最後一個選項。 – dasdom

回答

2

只需使用[TestAlert class]作爲目標而不是TestAlert

+0

是的,它的工作原理,謝謝! –

+0

我不能,因爲我沒有15的聲望。但我會回到這個頁面,並在我獲得15點聲望時接受它。 –

0

嘗試此操作如何。 你可以找到所有類型提供performSelector的:方法在這裏:

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

  • performSelector:
  • performSelector:withObject:
  • performSelector:withObject:withObject: - performSelector:withObject:afterDelay :
  • performSelector:withObject:afterDelay:inModes:
  • performSelectorOnMainT hread:withObject:waitUntilDone:
  • performSelectorOnMainThread:withObject:waitUntilDone:模式:
  • performSelector:onThread:withObject:waitUntilDone:
  • performSelector:onThread:withObject:waitUntilDone:模式:
  • performSelectorInBackground:withObject: