I feel the answers so far are missing the point of the question. Your error is saying that the Names
class doesn't implement isEqualToString:
method. This is being called (presumably) because the UITableViewCell
only changes the text
of its textLabel
if the string is different from what's being displayed, and it's performing this comparison using isEqualToString:
, because cell.textLabel.text
is an NSString
property.
However, you're not giving it an NSString
. You're giving it a Names
object, so of course it's not going to work. Since Names
is obviously a custom object, you must provide a method to extract a string representation from this object, and you must explicitly invoke that method yourself.
For example, you might implement a method called -asString
(which would be a horrible name, but this is to illustrate a point), that might look something like this:
- (NSString*) asString {
return [NSString stringWithFormat:@"This name is %@", aNameIvar];
}
You would then use it like this:
Name * thisName = [namesArray objectAtIndex:indexPath.row];
cell.textLabel.text = [thisName asString];
return cell;
The proper name for this method would be -stringValue
. -stringValue
is used on several Cocoa objects to return a string representation of the data that they hold, such as NSNumber
, NSCell
(Mac), etc.
EDIT:
Peter Hosey answered this exact question quite deftly in this StackOverflow.com question.