我有一个有2个视图的应用程序(表视图和详细信息视图)。我正在使用PHP文件从MySql中检索数据,表中的数据加载速度很快。我不知道如何更新表格!让我们说其中一个用户在详细信息视图中更新了他的名字,一旦他回到表视图就应该更改。
她是代码:
-(void)retrieveVideos {
NSString *myUrl = [NSString stringWithFormat:@"http://MyWebSite.com/phpfiles/data.php"];
NSURL *blogURL = [NSURL URLWithString:myUrl];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization
JSONObjectWithData:jsonData options:0 error:&error];
for (NSDictionary *bpDictionary in dataDictionary) {
ListOfObjects *list = [[ListOfObjects alloc]initWithVTheIndex:[bpDictionary objectForKey:@"TheIndex"] timeLineVideoUserName:[bpDictionary objectForKey:@"timeLineVideoUserName"] timeLineVideoDetails:[bpDictionary objectForKey:@"timeLineVideoDetails"] timeLineVideoDate:[bpDictionary objectForKey:@"timeLineVideoDate"] timeLineVideoTime:[bpDictionary objectForKey:@"timeLineVideoTime"] timeLineVideoLink:[bpDictionary objectForKey:@"timeLineVideoLink"] timeLineVideoLikes:[bpDictionary objectForKey:@"timeLineVideoLikes"] videoImage:[bpDictionary objectForKey:@"videoImage"] timeDeviceToken:[bpDictionary objectForKey:@"deviceToken"]];
[self.objectHolderArray addObject:list];
dispatch_async(dispatch_get_main_queue(), ^{
[spinner stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = FALSE;
});
}
if(jsonData != nil)
{
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if (error == nil)
NSLog(@"%@", result);
}
}
我的问题是如何使用新更新更新表格?
答案 0 :(得分:0)
您应该通过Delegate或KVO通知有关更新(通知) 在通知有关更新后,您应该使用新数据更新您的数据源(self.objectHolderArray),最后您必须致电:
[self.tableView reloadData];
或
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
答案 1 :(得分:0)
确保为tableview设置了dataSource和delegate方法。
self.tableView.dataSource = self;
self.tableView.delegate = self;
要更新UItable,您可以调用tableview的reloadData
方法。
ex:[self.tableView reloadData]
;
答案 2 :(得分:0)
在dispatch中重新加载tableview的数据:
dispatch_async(dispatch_get_main_queue(), ^{
[spinner stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = FALSE;
[self.tableView reloadData];
});