reloading a tableview when source is NSURLConnection and gets new data
I tabController app with uitableview getting NSURLconnection data and trying to display it. I can't figure out the issue. If I replace the connection with an array I'm storing all the drill-down works, but updating doesn't, So I think that the tableView end of things is fine. BUT:
If I put [[self.tableview] reloadData]; in the -(void) connectionDidFinishLoading:
This causes a loop of my parent row on the view. When you select a row it repopulates with the same row "Title", not the child of it. If I remove the [[self.tableview开发者_开发技巧] reloadData]; The tableDataSource3 is empty and does not get refreshed with URL data so I need it.I have NSLogs that are showing the update so I know it's getting updated.
If I put [[self.tableview] reloadData]; in the ViewDidAppear:
the View is empty until I move out of the table and back (the app is a tabcontroller with tableViews). If I add a row in the database and update via NSURL connection the tableView stays as it is, but if I select a row the new data that was updated appears in the pushed table.
If I put [[self.tableview] reloadData]; in the ViewWillAppear:
the View is empty until I move out of the table and back. however, the pushed child view is empty.
Any Ideas?
Here is the end of the NSURLconnection meth
-(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];
}
Here is the selection method:
- (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];
}
}
Kind of hard to track what you're saying...and your code needs formatting (above)
Try...
- Kick off your NSURLConnection request in -viewDidLoad
[[self tableView] reloadData];
should only be called inconnectionDidFinishLoading:
, or after any update to your data array outside of the NSURLConnection request.- in
connectionDidFinishLoading:
self.tableDataSource3 = [[NSArray alloc] initWithArray:test]; before the [[self tableView] reloadData];
精彩评论