3

What is the preferred method of creating detail view controllers for table rows? Let's say I have a UITableView with 100 rows in total. Each row can show a detail view controller. Should I re-allocate a new detail view controller for each row selected, or can I re-use the existing one using some sort of reset method?

Right now I have both options present in my code: For side swiping, I reset the same controller using a short fade animation.

For Core Data UITableView, I allocate a new controller for each row.

Should I try to reset the UITableView's detail controller when rows are selected, or is it a bad practice?

Update: I ended up allocating the controller for each table row selected. Within the controller, I added 2 extra buttons with fast forward and reverse icons. These allow the user to traverse the table data one by one, viewing all the details. I found that going back to the table to select one row after another to be too tedious. The extra buttons reset the controller for next/previous event. Since I'm using only one controller, I cannot user Core Animation to perform a view transtion. Instead, I scale the buttons on the controller to indicate that something has happened with "fast forward" has been tapped.

thank you!

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • I ended up allocating the controller for each table row selected. Within the controller, I added 2 extra buttons with fast forward and reverse icons. These reset the controller for next/previous event. Since I'm using only one controller, I cannot user Core Animation to perform a view transtion. Instead, I scale the buttons on the controller to indicate that something has happened with "fast forward" has been tapped. – Alex Stone Nov 16 '11 at 03:45

1 Answers1

1

I think the answer to your question depends on a number of factors, but it's definitely a very good thing you have both options currently present in your code. This gives you a chance to run Instruments and do a bit of memory profiling and allocation tracking.

The way I'd do it would be to check out what the difference is in memory between opening up one detail view controller and then instantiating 10, 20 or even all 100 detail view controllers.

If the memory footprint increases dramatically, I might be inclined to do the "reset the detail view" route.

If there's really only a small increase in memory for each detail view created (and it's faster to not have to reset everything on each table row selection), then I'd go that route.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I was under the impression that a detail view controller, pushed on the UINavigationController stack is de-allocated when the user taps the "back" button. So I would expect the memory to be reclaimed in the case of allocating for each row. I would expect that a pre-allocated and resettable controller would take up more space for longer periods of time, but would load much faster. – Alex Stone Nov 14 '11 at 16:55