2013-02-07 18 views
-1

我想將兩個參數傳遞給帶有NSThread的方法。我嘗試使用this third answer。但不幸的是,代碼運行不正常,因爲andKeys: 方法不可用。在目標c中傳遞帶有NSthread的扇區中的多個參數

[NSThread detachNewThreadSelector:@selector(DownloadCheckServerPath:DirectoryName:) toTarget:self withObject:"How to pass two objects"]; 

那麼我應該怎樣在扇區中通過NSThread調用-(void)DownloadCheckServerPath:(NSString *)serverPath DirectoryName:(NSString *)directoryName這個方法。 ?

+1

[此問題已被問及之前回答](http://stackoverflow.com/questions/8439052/ios-how-to-implement-a-performselector-with-multiple-arguments-and-with-afterd/8439084#8439084) –

回答

0

您不能將多個參數傳遞給由此消息發送調用的方法。解決方法:使用集合。一個論點綽綽有餘。

- (void)reallyCallMethod:(NSDictionary *)dict 
{ 
    [self downloadCheckServerPath:dict[@"path"] directoryName:dict[@"dir"]]; 
} 

[NSThread detachNewThreadSelector:@selector(reallyCallMethod:) 
         toTarget:self 
         withObject:@{ @"path" : @"/foo/bar", @"dir" : @"baz" }]; 

另外:不以大寫字母開始選擇器名稱。這僅適用於類(並且它的確很難看,是不是嗎?)

+0

yesh!現在功能正常工作。謝謝你的回答。我仍然是目標c的初學者。那是y。 :) – Himesh

0

在這種情況下,我通常會創建一個NSDictionary並傳遞它。在函數中,我讀取字典並獲取所需的所有元素。