views:

86

answers:

2

I have a view controller that gets presented modally and changes some data that effects the data in a uitableview in the modal's parent view controller (a table view).

I call the tableview's reloadData method when the parent view reappears. I have confirmed that this code gets hit with a break point. My trouble is, reloadData isn't working. Here's the kicker - if I don't use reuseIdentifiers in the - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath method, the data reloads correctly. It looks like the reuseIdentifier is to blame.

I really want to continue to use the reuseIdentifier for my cells - how do I make this work?

A: 

The problem is unlikely to do with the reuse identifier. Please post your code for your tableView:cellForRowAtIndexPath: method.

Shaggy Frog
+1  A: 

Got it figured, and you're right, it's not the reuseIdentifer.

I was nesting the content assignment right below the cell allocation like so:

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    cell.accessoryType = [targetRow.children count] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;

// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat: targetRow.title];
}

Since the dequeued cell was found, the content wouldn't get updated.

I changed it to this and all works great now...

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}

cell.accessoryType = [targetRow.children count] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;

// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat: targetRow.title];
retailevolved
I think that's a common mistake when you first start dealing with UITableViews. I know I've done the same thing.
Shaggy Frog
hi, can you tell me what is the meaning of this line "cell.accessoryType = [targetRow.children count] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;" ? this question mark on the syntax is strange to me... how do I learn to use this ?
Digital Robot
I've always referred to it as an "inline if" statement, not sure if that is the technical term or just geek slang. Basically, it is the same as tapping out: if ([targetRow.children count]) { cell.accessoryType = UITableViewCellAccessoryDisclosure; } else { cell.accessoryType = UITableViewCellAccessoryNone; } - Another good tool for lazy programmers :) Also much cleaner to read.
retailevolved