Tuesday, September 7, 2010

Change Image of Cell on selection in TableView in objective C (Iphone)

using below function we can change image of cell/row when user click/select on row/cell of tableview in objective-C



- (void)tableView:(UITableView *)tableView

didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSArray *listData =[self.tableContents objectForKey:

[self.sortedKeys objectAtIndex:[indexPath section]]];

NSUInteger row = [indexPath row];

NSString *rowValue = [listData objectAtIndex:row];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

cell.image = [UIImage imageNamed:@"checkbox-checked.png"];

NSString *message = [[NSString alloc] initWithFormat:rowValue];

UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"You selected"

message:message delegate:nil

cancelButtonTitle:@"OK"

otherButtonTitles:nil];

[alert show];

[alert release];

[message release];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

No comments:

Post a Comment