2012-09-18 47 views
0

是否可以使用此方法並傳遞一個對象?有了這個代碼,我得到這個錯誤:iOS performSelector onThread with object

-[myApp hideUpdateView]: unrecognized selector sent to instance 0x8b6a880 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[myApp hideUpdateView]: unrecognized selector sent to instance 0x8b6a880' 

它從來沒有達到hideUpdateView方法...

代碼:

NSArray *array = [NSArray arrayWithObjects:@"1", @"2", nil]; 
[self performSelector:@selector(hideUpdateView) onThread:[NSThread mainThread] withObject:array waitUntilDone:YES]; 



- (void) hideUpdateView: (NSArray *) inputArray 
{ 
    int catCount = [[inputArray objectAtIndex:0] intValue]; 
    //hide it 
} 
+4

我一直在iOS開發一段時間,但它應該是'@selector(hideUpdateView :) '? – Pete

+0

@Pete當然應該。 – 2012-09-18 18:57:20

+0

@ H2CO3涼爽。而且我還沒有在2年內寫出一行Obj-C。我應該把它作爲回答,而不是賺取積分。 – Pete

回答

6

你錯過了從選擇結束結腸名稱。 (請閱讀Objective-C的turorial。冒號是選擇器名稱的一部分。)

[self performSelector:@selector(hideUpdateView:) onThread:[NSThread mainThread] withObject:array waitUntilDone:YES]; 
              ^
            Note the colon here 
+0

哦,男人感謝傢伙愚蠢的錯誤。它做到了。所以當你調用的方法有參數時,你必須有':'?因爲我的大多數正常performSelector調用不具有':',它工作正常。 – boostedz06

+0

@userXXX是的。每個參數都需要冒號。考慮'@selector(performSelector:onThread:withObject:waitUntilDone:)'本身的名稱... – 2012-09-18 19:03:20

+0

(請注意,您可以接受幫助的答案。) – 2012-09-18 19:03:45