Saturday, 14 September 2013

Different UITableViewCells doing different things when tapped

Different UITableViewCells doing different things when tapped

I have a UITableView with 5 cells. When each are tapped, they do different
things. But for now (in order for the code to not be too long), when
tapped, they all call out an NSLog.
Here is the code.
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *newCell = [_randomCells
cellForRowAtIndexPath:indexPath];
if ([(newCell) isEqualToString:@"Random cell 1"]) {
NSLog(@"foo bar 1.");
} else if ([(newCell) isEqualToString:@"Random cell 2"]) {
NSLog(@"foo bar 2.");
} else if ([(newCell) isEqualToString:@"Random cell 3"]) {
NSLog(@"foo bar 3.");
} else if ([(newCell) isEqualToString:@"Random cell 4"]) {
NSLog(@"foo bar 4.");
} else if ([(newCell) isEqualToString:@"Random cell 5"]) {
NSLog(@"foo bar 5.");
}
}
I figured that this would be the most appropriate way to detect tapped
UITableViewCells with Storyboards since I couldn't find another way to do
it.
In all five if statements, however, I receive this error message:
No visible @interface for 'UITableViewCell' declares the selector
'isEqualToString:'
How would I fix this issue? Thanks in advance.
Please note, I am using typing the code with Objective-C ARC and using
Storyboards.

No comments:

Post a Comment