简体   繁体   中英

UITableView doesn't remember its scroll position

I can post code, though I'm not quite sure where to start. I have a UITableView with custom cells, in the middle tier of a three-level UINavigationView scheme. When I drill down to the bottom level and see details about my data, then use the top-left back button, my table view comes back scrolled all the way to the top, rather than scrolled down to where it was when I last saw it. Where should I look about this?

EDIT:

Here's the code in the EventsTableViewController to load an instance of EventsDetailViewController and push it on the navigation controller:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSMutableArray *events = [DataManager sharedDataManager].eventList;

    Event *selectedEvent = [events objectAtIndex:[indexPath row]];
    EventsDetailViewController *detailController = [[EventsDetailViewController alloc] initWithNibName:@"EventsDetailView" bundle:nil];
    [detailController loadEvent:selectedEvent];

    MyAppDelegate *del = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
    [del.navigationController pushViewController:detailController animated:YES];
    [detailController release];

}

There's nothing in my EventsTableViewController about reloading the table, as far as I can see--I haven't implemented viewWillAppear or viewDidLoad or any of those.

Are you by any chance reloading the table where you shouldn't be? In the ViewWillAppear method for example?

I was accidentally instantiating a new copy of my table view whenever I hit this level of the navigation. That's all fixed now and this isn't a problem anymore.

I have a very similar question. When I go to the chatView, which is a UIViewController belonging to the navigationController and has a tableView as a subview, and then I scroll to some point, and then I go back, and then I go back to the chatView, it starts at the top again. I am allocing the tableView in loadView of the chatView, so the tableView gets realloced everytime I come back. But, isn't this standard? How do I just always scroll to the bottom like the iPhone Messages app and show the scroll bar for a few seconds at the bottom?

Here's the code:

http://github.com/acani/acani-chat/blob/master/Lovers2/Classes/ChatViewController.m#L184

Thanks!

Matt

are you doing:

[self presentViewController:navController animated:YES completion:nil];

where self is tableviewcontroller? give this a try:

[self.navigationController presentViewController:navController animated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM