Developer
Developer

Reputation: 1019

how to get cell value in iphone?

In my iphone application I have 4 cell in uiTable, and each cell having Integers values(10, 12, 13, 14).How to retrieve the integer value while I click on each cell? And how to put if condition to check whether the value of the cell is same or not? I.e.

if(cell value==condition){

}

Upvotes: 1

Views: 576

Answers (1)

Niels Castle
Niels Castle

Reputation: 8069

In the didSelectRowAtIndexPath method in your UITableViewController simply extract the labels text value.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *s = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text];
    NSLog(@"String is: %@", s);

    int i = [s intValue];
    NSLog(@"This is the int value: %d", i);

    // Compare string or int to other value...
}

Upvotes: 1

Related Questions