views:

50

answers:

3

Hi,

I'm working on creating a grouped table view. The data is being loaded alright, but in the grouped view there are a lot of white empty spaces. They get populated after I scroll up and down a few times. Help?

Here's my getCellForRowIndexAtPath method:

static NSString *Id= @"CustomDiagChargeID";
CustomCellDiagCharges *cell = (CustomCellDiagCharges *)[tableView dequeueReusableCellWithIdentifier:Id];
if(cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellDiagCharges" owner:self options:nil];
    for (id oneObject in nib) {
        if([oneObject isKindOfClass:[CustomCellDiagCharges class]])
            cell = (CustomCellDiagCharges *) oneObject;
    }
}

NSUInteger row = [indexPath row];
DiagDetails *rowData = [preferences getDiagElementAt:indexPath.section row:row];
cell.code.text = rowData.ICD9Code;
cell.desc.text = rowData.ICD9Desc;  
return cell;

Thanks,
Teja.

A: 

For one thing, you shouldn't declare Id as static. The pointer will be invalid after the first event loop completes and the string is deallocated.

Update: This is incorrect. See below.

Tom
it's a string constant, from "String Programming Guide": The simplest way to create a string object in source code is to use the Objective-C @"..." construct:NSString *temp = @"/tmp/scratch";Note that, when creating a string constant in this fashion, you should avoid using anything but 7-bit ASCII characters. Such an object is created at compile time and exists throughout your program’s execution. The compiler makes such object constants unique on a per-module basis, and **they’re never deallocated**, though you can retain and release them as you do any other object.
jessecurry
Wow, right you are. Edited.
Tom
+1  A: 

When your cell contents change due to scrolling, that's almost always caused by a problem with your cell identifiers. Inspect your CustomCellDiagCharges object in CustomCellDiagCharges.xib and make sure its Identifier field matches the cell identifier you're using in your code (CustomDiagChargeID).

Also, if you have other tables in your app, make sure you're not using the same cell identifier with another UITableViewCell subclass.

cduhn
No luck there, the identifier is correct. It's a grouped tableView if that helps?
Tejaswi Yerukalapudi
Hmm... That's surprising. This is the first time I've heard of scrolling revealing inconsistencies that weren't caused by reuse identifier issues. Try putting NSLog(@"section: %d, row: %d, code: '%@', desc: '%@'", indexPath.section, indexPath.row, cell.code.text, cell.desc.text); immediately before return cell;. Are the text properties of your labels populated when the cells appear to be blank?
cduhn
A: 

I was playing around with background and cell alphas and somehow all of the cells are loading now. Not really sure what the problem was. Oh well, software.

Tejaswi Yerukalapudi