UITableView Cell Selection

by / Wednesday, 07 August 2013 / Published in Iphone

Each row of of a UITableView is represented by a UITableViewCell. A particular row or a UITableViewCell can be selected from multiple cells of a UITableView. To add action on selection of a row or cell, write the following method-

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

{

[tableView reloadData];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

cell.contentView.backgroundColor=[UIColor blackColor];

cell.textLabel.backgroundColor=[UIColor blackColor];

cell.textLabel.textColor=[UIColor whiteColor];

cell.textLabel.text=[NSString stringWithFormat:@"cell %d selected",indexPath.row+1];

}

TOP