所以,我試圖連接到遠程服務器來獲取和顯示數據。在viewDidLoad
我使用NSThread
呼叫被叫doSomething
NSThread無法加載選擇器方法
- (void)doSomething
{
@autoreleasepool
{
NSMutableURLRequest *httpRequest = [NSMutableURLRequest requestWithURL:someURL];
[httpRequest setHTTPMethod:@"POST"];
[httpRequest setValue:[NSString stringWithFormat:@"%d", httpRequestParametersClean.length] forHTTPHeaderField:@"Content-Length"];
[httpRequest setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[httpRequest setHTTPBody:httpRequestParametersClean];
(void)[[NSURLConnection alloc] initWithRequest:httpRequest delegate:self];
for (NSString* key in response)
{
// loop through returned values
}
}
}
功能
在viewDidLoad
的代碼是
[NSThread detachNewThreadSelector:@selector(someURL) toTarget:self withObject:nil];
然後,我有一個REFRESH
按鈕,當通過簡單地說[self doSomething]
doSomething
以及
我的問題是,當視圖加載時,來自服務器的響應爲空。直到我點擊刷新按鈕,我仍然沒有迴應。奇怪!我究竟做錯了什麼?
我可以看到,NSThread調用getTableViewCells而不是doSomething –
這是一個錯字。即使當我確定該線程正在調用正確的函數時,問題依然存在 –