Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ataylor2009

macrumors member
Original poster
Jan 27, 2009
78
0
I've got a detail view that consists of a table view with a few rows of data. I can fill the rows just fine, and moving back and forth from the parent view to the subview works too. This detail view should allow the user to select a single value, placing a checkmark accessory in the cell and then returning to the parent view (where the selected value becomes the cell.textLabel.text property of the cell from which the detail view was called). This all works as of right now.

However, when the user taps the cell in the parent view to go back to the detail view (to change their selection), my checkmark has disappeared and I cannot for the life of me figure out how to make it stay.

Here's my cellForRowAtIndexPath: method:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        }

    NSString *labelText = [[phones objectAtIndex:indexPath.row] valueForKey:@"phoneNumberLabel"];
    cell.textLabel.text = labelText;
    NSString *currentLabel = [ruleBuilder.tableView cellForRowAtIndexPath:selectedIndexPath].textLabel.text;
    if (labelText == currentLabel) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }

    NSString *detailText = [[phones objectAtIndex:indexPath.row] valueForKey:@"phoneNumber"];
    cell.detailTextLabel.text = detailText;
    return cell; }

When a run this code in the debugger, it shows that labelText is equal to currentLabel - but the checkmark accessory is not being applied to the cell.

I've checked out Apple's sample code for exclusive-list management in Table View Programming Guide, but the snippet seems incomplete, and I can't find the related code in Apple's sample code. This doesn't seem like it ought to be that hard to do.
 
You are using == to compare strings. Don't. Look in the documentation for the correct way to compare them (hint do a search for Equal in the NSString page).
 
Doh! (Head-slapping sound, followed by crickets chirping in the background...)

"Thanks," he said sheepishly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.