Showing posts with label UITableView tableView didUnhighlightRowAtIndexPath example. Show all posts
Showing posts with label UITableView tableView didUnhighlightRowAtIndexPath example. Show all posts

Saturday, June 8, 2013

UITableView tableView didUnhighlightRowAtIndexPath example in Objective C (iOS).


UITableView tableView didUnhighlightRowAtIndexPath

Tells the delegate that the highlight was removed from the row at the specified index path.

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

Parameters of [UITableView tableView didUnhighlightRowAtIndexPath]
tableView
The table-view object that removed the highlight from the cell.
indexPath
The index path of the row that had its highlight removed.

UITableView tableView didUnhighlightRowAtIndexPath example.

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    UIImageView *accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessory.png"]];
    cell.accessoryView = accessoryView;
}

Example of [UITableView tableView didUnhighlightRowAtIndexPath].
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
  // Add your Colour.
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
    [self setCellColor:[UIColor whiteColor] ForCell:cell];  //highlight colour
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
  // Reset Colour.
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
    [self setCellColor:[UIColor colorWithWhite:0.961 alpha:1.000] ForCell:cell]; //normal color

}

- (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell {
    cell.contentView.backgroundColor = color;
    cell.backgroundColor = color;
}

End of UITableView tableView didUnhighlightRowAtIndexPath example article.