Reputation: 4974
I have a Core Data row that contains information regarding selected rows in a UITableView. The UITableViewCell value was obtained from an array of strings which is the 1st compare value; a NSString (which was stored in a Core Data row and is now displayed in a UITextField) is the 2nd compare value.
I want to compare the cell.textLabel to the textField so I can set the cell's accessory checkmark.
This is my code; the comparison is not working (I have verified the first comparison should be true):
if([cell.textLabel isEqual: soServices.text]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
}
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
I'm assuming my compare is incorrect, but have not found anything on SO or Google to indicate the correct way to do the compare. So, how do I compare the cell.textLabel to a NSString?
Upvotes: 0
Views: 286
Reputation: 1052
if([cell.textLabel isEqual: soServices.text]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
}
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
You're currently comparing a label to a string object, using titleLabel
's text
property will let you to use the isEqualToString:
method allowing you to successfully compare the two.
Upvotes: 3
Reputation: 2304
Try this:
if([cell.textLabel.text isEqualToString: soServices.text]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
break;
}
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
Upvotes: 3