How do I read intValue of an array of NSIndexpaths through indexPathsForVisibleRows?
By the way, why do visibleCells and indexPathsForVisibleRows not work before if (cell == nil) function?
Here is my code:
In the cellForRowAtIndexPath method:
static NSString *identifierString;
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:identifierString];
// when I use visibleCells and indexPathsForVisibleRows here, the app crashes
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierString] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
// when I use visibleCells and indexPathsForVisibleRows here, the app works
//cell implementation here
return cell;
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathis where the tableview gets populated with cells. If you try to reference visible cells before they have been created, which is done within the if-statement, then the app crashes.The
alloccommand allocated memory for the cell to be created and then it gets initialized with certain parameters. This method gets called as many times as you designate innumberOfRowsInSection.So that you don’t recreate all the cells again and again the if-statement checks if the cell does exist and only if it is nil creates a new one to take the place.
To get the
introw value of an IndexPath you can use it’s row property. For example:Hope this helps