2014-01-10 23 views
0

嗨我的問題是,我從Web服務獲取響應,當我解析它並添加到表並重新加載表視圖它不刷新。雖然如果我在鍵盤上調用[table reload],它會在那裏得到更新。有人能告訴我,如果我在想念什麼如何表接收響應時重新加載ios數據

這就是我要做的

- (void) longPoll { 
//create an autorelease pool for the thread 
    @autoreleasepool { 

    NSLog(@"polling"); 
    VSAppDelegate *var = (VSAppDelegate*)[[UIApplication sharedApplication] delegate]; 
    //compose the request 
NSError* error = nil; 

NSHTTPURLResponse* response = nil; 


    //send the request (will block until a response comes back) 
NSData* responseData = [NSURLConnection sendSynchronousRequest:request           returningResponse:&response error:&error]; 
    NSLog(@"polling response is %d",response.statusCode); 

//pass the response on to the handler (can also check for errors here, if you want) 
    [self performSelectorOnMainThread:@selector(dataReceived:) withObject:responseData waitUntilDone:YES]; 
} 

[self performSelectorInBackground:@selector(longPoll) withObject: nil]; 
} 

- (void) startPoll { 

[self performSelectorInBackground:@selector(longPoll) withObject: nil]; 
} 
- (void) dataReceived: (NSData*) theData 
{ 
    //process the response here 
    NSError *error = nil; 
    NSLog(@"polling data is %@",[[NSString alloc] initWithData:theData  encoding:NSUTF8StringEncoding]); 
     NSLog(@"polling data is %@",[[theData base64EncodedString]base64DecodedString]); 
    NSDictionary *notifDic= [NSJSONSerialization JSONObjectWithData:theData options:kNilOptions error:&error]; 

    //VSViewControllerSplit *split = [[VSViewControllerSplit alloc]init]; 
    [self RecieveFunction:notifDic]; 

} 
+0

你是否檢查過你的數據源是否有正確的數據,並且它是否正確鏈接到你的tableview? – user1781290

+0

是的,這是正確的問題是我把它添加到表中,然後調用它,但沒有任何反應。是的,表格視圖不是零,因爲我能夠在我調試代碼時看到它。此外,當我點擊文本字段它去鍵盤確實顯示通知,即時通訊調用[表重新加載數據],並有它得到重新加載 – BackStabber

+0

後ur代碼你先試過什麼,那麼只有我們能夠找到問題 – CoolMonster

回答

0

嘗試

dispatch_async(dispatch_get_main_queue(), ^{ 

      [tablrView reloaddata]; 

          }); 
0

dataReceived方法似乎並沒有被調用reloadData。儘管如此,我認爲RecieveFunction方法確實可行,但您應該確認。沒有看到RecieveFunction很難說。

更根本的問題似乎是dataReceived方法創建的VSViewControllerSplit一個新實例,調用它的RecieveFunction方法,然後讓這種新VSViewControllerSplit實例掉出的範圍(如果使用ARC,得到釋放,除非你推給它,提交它等)。你大概不想每創建一個新的VSViewControllerSplitlongPoll調用dataReceived,而只是引用現有的實例。

+0

嗨,是啊謝謝我做了保持在vsviewcontrollersplit功能,但問題是我的代表零,當我刷新它從接收數據,然後它回來 – BackStabber

+0

@BackStabber是的,因爲你實例化一個新的VC每次,它將是'無'。 (這就是爲什麼我早些時候詢問表視圖是否爲'nil')。你沒有說你的上面的代碼片段是在哪個類中實現的,但如果它不是'VSViewControllerSplit'本身,那麼你應該創建一個'weak '屬性來保存對現有VSViewControllerSplit實例的引用,而不是每次都創建一個新實例。 – Rob

+0

即時通訊仍然得到datasoure作爲無dataRecieved :( – BackStabber