dequeueReusableCellWithIdentifier bug ?
Hi,
I'm currently using AQGridView for a project. I have 16 cells in the grid. dequeueReusableCellWithIdentifier should then return 16 nil cells, but I only get 8...
Here is my cellForItemAtIndex method :
- (AQGridViewCell_) gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index
{
static NSString_ myIdentifier = @"MiniPola";
ImageDemoGridViewCell\* cell = (ImageDemoGridViewCell_)[aGridView dequeueReusableCellWithIdentifier:myIdentifier];
if (cell == nil)
{
//Should pass here 16 times but only does 8 times...
cell = [[[ImageDemoGridViewCell alloc] initWithFrame:CGRectMake(0, 0, 171, 199) reuseIdentifier:myIdentifier] autorelease];
// I would Like to set my cell's Photo and Profile here to get a smooth scrolling...
}
[cell setTitle:[[contentArray objectAtIndex:index]objectForKey:@"title"]];
[cell setPhoto:[[contentArray objectAtIndex:index] objectForKey:@"picture"]];
[cell setProfile:[[[contentArray objectAtIndex:index] objectForKey:@"from"] objectForKey:@"picture"]];
NSNumber_ temp = [NSNumber numberWithInt:index];
cell.cellIndex = temp;
return cell;
}
Thanks for your help !
I think the times the grid view does not have a cached and reusable cell depends on the size of the grid view, the number of cells it ought to show, etc., and if you’re using the same reuse identifier, then it’s almost guaranteed to be working… If you want every single cell cached and no reusing, you can consider using [NSString stringWithFormat:@"%@-%i", myIdentifier, index] — but this is really not recommended because cell creation is relatively costly.