您好我的问题是我从Web服务获得响应,当我解析它并添加到表并重新加载表视图时,它不令人耳目一新。虽然如果我调用键盘中的[table reload],它会在那里更新。有人能告诉我我是否遗漏了什么
这就是我想要做的事情
- (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 :(得分:0)
试试吧
dispatch_async(dispatch_get_main_queue(), ^{
[tablrView reloaddata];
});
答案 1 :(得分:0)
dataReceived
方法似乎没有调用reloadData
。我会假设RecieveFunction
方法确实如此,但你应该确认一下。没看到RecieveFunction
就很难说。
更基本的问题似乎是dataReceived
方法正在创建VSViewControllerSplit
的新实例,调用其RecieveFunction
方法,然后让这个新的VSViewControllerSplit
实例超出范围(如果使用ARC,除非你按下它,呈现它等,否则将被取消分配)。您可能不希望每次VSViewControllerSplit
调用longPoll
时都创建新dataReceived
,而只是引用现有实例。