1

I have a table view, onclick of 7th row, I push another view. Then when I come back using pop, tableview is reloaded automatically in ios8. It does not happen is ios 7.

Problem is cellForRow and HeightForRow for 0,1,2,3 cell is not called. Hence table scrolls the 7th row up, and not visible. 9,10,11 cells are visible.

I want table to stay as it was when I come back to that view.

I saved selectedIndex and scrolled table to particular index in viewWillAppear.

[self.table_exhibitorProfile scrollToRowAtIndexPath:self.selectedIndexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];

It shows 7th cell, but its position is not same as it was. It goes to top.

Durgaprasad
  • 1,910
  • 2
  • 25
  • 44
  • Are you calling [tableView reloadData] in ViewDidAppear / ViewWillAppear ? – Mrunal Dec 31 '14 at 07:23
  • No. I dint call. It is working fine in ios7. – Durgaprasad Dec 31 '14 at 08:54
  • Yeah, I've run into this issue as well. I'm populating table rows from core data but I'm not linking them explicitly, just using core data as if it were an array of dictionaries or something. However, if I manipulate the core data (add or delete rows) it causes my tableview to reload. Not sure why. – William T. Mar 22 '15 at 20:15
  • Do you set `self.tableView.estimatedRowHeight` value? – avdyushin Apr 06 '15 at 13:48
  • Same problem here. Demo project in case you want to fork and post a solution: https://github.com/cyrille-legrand/ios8-tableview-autoreload – Cyrille Apr 28 '15 at 07:27
  • And it does not "reload" fully, I mean it inserts rows in a bizarre way. Check my project and tap the "Insert row on top" button to see what I mean. – Cyrille Apr 28 '15 at 07:31

2 Answers2

1

It shouldn't be reloading unless you tell it to. It's not automatically reloading in iOS 8 for me.

The only possibilities that I can come up with are that

  1. you're using CoreData, an NSFetchedResutsController, and the same managedObjectContext in both view controllers. If something changes in the managedObjectContext in the second view controller, when you pop back, the fetchedResultsController will reload the table, or

  2. you're calling tableView.reloadData() in viewWillAppear() or viewDidAppear().

trevorj
  • 2,029
  • 1
  • 16
  • 11
  • I din't use core data. table rows has values from local array. Next view is totally separate. I only send it a key, and data is fetched from JSon. About viewWillAppear ans viewDidAppear, I dint call table reload. – Durgaprasad Dec 31 '14 at 08:53
  • Did you try commenting out the `scrollToRowAtIndexPath:` line and seeing if it still automatically reloaded? That may be messing things up... – trevorj Dec 31 '14 at 09:00
  • Yes. That I added later. – Durgaprasad Dec 31 '14 at 09:57
  • 1
    Man, that is tough. Is there anything in your data model that might be messing things up? I was using an enum in my data model once and the way I was handling it ended up causing a problem similar to the one you're describing. If the table view in the second VC only had one row, when I popped back to the initial VC, that one also only had one row. Don't know if it'll help, but you could look to see if there's anything in your model that might cause a similar effect. – trevorj Dec 31 '14 at 10:48
  • 1
    it's definitely reloading. @trevorj you are probably just breakpointing on a different method. Set the breakpoint on numberOfSectionsInTableView. This is very easy to reproduce. Create a template Master-Detail project, or grab from my github https://github.com/MaxMacleod/TableReloadTest1 – Max MacLeod Mar 05 '15 at 11:13
  • HI @trevorj i am facing issue on ios 8 table reload automatically. How can i stop that thing b'cz i need table reload on some condition on viewWillAppear method . Please can you help me..!! – Jay Mehta Apr 22 '15 at 14:43
0

I had the same problem and this is how I fixed it:

According to the Apple docs:

UITableView overrides the layoutSubviews method of UIView 
so that it calls reloadData only when you create a new 
instance of UITableView or when you assign a new data source.

In my case I was setting the table view's dataSource to nil in viewWillDisappear: and setting it back to self in viewWillAppear: thus causing the data to be reloaded.

The 'automatic' reload went away when I moved the dataSource assignment to viewDidLoad

Hope this helps!

LuisCien
  • 6,362
  • 4
  • 34
  • 42