Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 25, 2008, 03:39 PM   #1
forrestgrant
macrumors member
 
Join Date: Jun 2008
Table View

I have a table view, and cells are set up differently based on which section they are in. The trouble is, when I scroll, it wants to reset each cell that is off screen. This makes it crash if say, cell 0, 1, 2 are off screen then I scroll up, and it tries to put section 1 cell 1 into section 2 cell 1, and everything breaks.

I apologize for this being vague, but I am counting on someone having the exact same problem, I think it is relatively common.
forrestgrant is offline   0 Reply With Quote
Old Aug 25, 2008, 03:58 PM   #2
davedelong
macrumors member
 
Join Date: Sep 2007
Location: Right here.
Send a message via AIM to davedelong
Yep, that's because the iPhone is trying to be smart about loading cells. When a cell is scrolled offscreen, it gets put into the reuse queue. Then when it comes time to draw a new cell, it looks up in the reuse queue to see if there are any available for a particular type.

Most likely you left the default identifier as "MyIdentifier". If you want to have a different kind of cell for each section, you need to give them different identifiers. You can determine this based off the NSIndexPath that's passed into the cellForRow datasource method.

That way, the iPhone will only look for cells with the appropriate identifier when it wants to reuse them.

HTH,

Dave
davedelong is offline   0 Reply With Quote
Old Aug 25, 2008, 04:48 PM   #3
Taum
macrumors member
 
Join Date: Jul 2008
I don't think you *have* to reuse cells. You could simply create new cells and not bother with reusing the old ones. But then you probably lose the performance gain for not re-creating every cell. As always, it's up to you to choose
Taum is offline   0 Reply With Quote
Old Aug 25, 2008, 04:50 PM   #4
davedelong
macrumors member
 
Join Date: Sep 2007
Location: Right here.
Send a message via AIM to davedelong
Quote:
Originally Posted by Taum View Post
I don't think you *have* to reuse cells. You could simply create new cells and not bother with reusing the old ones. But then you probably lose the performance gain for not re-creating every cell. As always, it's up to you to choose
Correct. You don't have to reuse old cells. The reuse queue is even smart enough that it won't store more than a certain number of cells.

The idea is that alloc'ing new cells can be somewhat expensive, and this is a way to get around that.
davedelong is offline   0 Reply With Quote
Old Aug 26, 2008, 09:55 AM   #5
forrestgrant
Thread Starter
macrumors member
 
Join Date: Jun 2008
Just what I needed, thanks!
forrestgrant is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Table View to Detail View hammy35 iPhone/iPad Programming 3 Apr 16, 2014 01:33 AM
View-based table view losing selection highlight Starfox Mac Programming 1 Nov 28, 2012 01:02 AM
Find location of table view cell that calls view controller moonman239 iPhone/iPad Programming 3 Nov 24, 2012 05:31 PM
View based table view layout woes Starfox Mac Programming 0 Nov 8, 2012 10:50 PM
Pushing to a Detail View from a Table View Cell using Xcode Storyboard xcodeApp10 iPhone/iPad Programming 2 Sep 17, 2012 03:45 PM

Forum Jump

All times are GMT -5. The time now is 10:42 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC