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

Saturday, June 8, 2013

UITableView tableView didHighlightRowAtIndexPath example in Objective C (iOS).


UITableView tableView didHighlightRowAtIndexPath

Tells the delegate that the specified row was highlighted.

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

Parameters of [UITableView tableView didHighlightRowAtIndexPath]
tableView
The table-view object that highlighted the cell.
indexPath
The index path of the row that was highlighted.

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

    if (!_isFromHighlight)
    {
        [self selectRowAtIndexPath:indexPath];
    }
    _isFromHighlight=NO;
}

-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self selectRowAtIndexPath:indexPath];
    _isFromHighlight=YES;
}

Example of [UITableView tableView didHighlightRowAtIndexPath].
 - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
 {
     [cell setBackgroundColor:[UIColor redColor]];  
 }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   [cell setBackgroundColor:[UIColor greenColor]];
}

UITableView tableView didHighlightRowAtIndexPath example.
- (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 didHighlightRowAtIndexPath example article.