【发布时间】:2010-10-22 23:08:59
【问题描述】:
我使用 uitableview 的 tabController 应用程序获取 NSURLconnection 数据并尝试显示它。我无法弄清楚这个问题。如果我用数组替换连接,我将存储所有向下钻取的工作,但更新不会,所以我认为 tableView 的结果很好。但是:
如果我把 [[self.tableview] reloadData];在 -(void) connectionDidFinishLoading:
这会导致我的父行在视图上出现循环。当您选择一行时,它会重新填充同一行“标题”,而不是它的子行。如果我删除 [[self.tableview] reloadData]; tableDataSource3 是空的,没有用 URL 数据刷新,所以我需要它。我有 NSLogs 显示更新,所以我知道它正在更新。
如果我把 [[self.tableview] reloadData];在 ViewDidAppear 中:
在我移出表格并返回之前,视图是空的(该应用程序是一个带有 tableViews 的 tabcontroller)。如果我在数据库中添加一行并通过 NSURL 连接进行更新,tableView 将保持原样,但如果我选择一行,则更新的新数据将出现在推送的表中。
如果我把 [[self.tableview] reloadData];在 ViewWillAppear 中:
在我离开桌子并返回之前,视图是空的。但是,推送的子视图是空的。
有什么想法吗?
NSURLconnection方法到此结束
-(void) connectionDidFinishLoading:(NSURLConnection *)conn3 {
~ JSON STUFF~
NSArray *test = [json objectForKey:@"Rows"];
tableDataSource3 = [[NSArray alloc] initWithArray:test];
[json release];
[conn3 release];
self.receivedData =nil;
[[self tableview] reloadData];
}
这里是选择方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource3 objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
if([Children count] == 0) {
ItemDetailViewController *dvController = [[ItemDetailViewController alloc] initWithNibName:@"ItemDetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
ThirdTab *rvController = [[ThirdTab alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
rvController.CurrentLevel3 += 1;
rvController.CurrentTitle3 = [dictionary objectForKey:@"Title"];
[self.navigationController pushViewController:rvController animated:YES];
rvController.tableDataSource3 = Children;
[rvController release];
}
}
【问题讨论】:
标签: iphone uitableview nsurlconnection