[英]reloading a tableview when source is NSURLConnection and gets new data
我使用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];
}
}
有點難以追蹤您的意思...並且您的代碼需要格式化(以上)
嘗試...
[[self tableView] reloadData];
只能在connectionDidFinishLoading:
調用,或者在NSURLConnection請求之外對數據數組進行任何更新后調用。 connectionDidFinishLoading:
self.tableDataSource3 = [[NSArray alloc] initWithArray:test]; before the [[self tableView] reloadData];
self.tableDataSource3 = [[NSArray alloc] initWithArray:test]; before the [[self tableView] reloadData];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.