Saturday, June 8, 2013

UITableViewCell selectionStyle example in Objective C (iOS).


UITableViewCell selectionStyle

The style of selection for a cell.

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Discussion of [UITableViewCell selectionStyle]
The selection style is a backgroundView constant that determines the color of a cell when it is selected. The default value is UITableViewCellSelectionStyleBlue. See “Cell Selection Style” for a description of valid constants.

UITableViewCell selectionStyle example.
in didSelectRowAtIndexPath

UIActivityIndicatorView *cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cellActivityIndicator setCenter:CGPointMake(20, 20)];
[cellActivityIndicator startAnimating];
[cell addSubview:cellActivityIndicator];
where, here [cellActivityIndicator setCenter:CGPointMake(20, 20)]; you enter position indicator in cell.

and in cellForRowAtIndexPath

[cell setSelectionStyle:UITableViewCellSelectionStyleGray];


Example of [UITableViewCell selectionStyle].
In cellForRowAtIndexPath use this code:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

[cell.myLabel setHighlightedTextColor: [UIColor whiteColor]]; // for all your labels
Hope this will work for you.


UITableViewCell selectionStyle example.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // A case was selected, so push into the CaseDetailViewController
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (![cell selectionStyle] == UITableViewCellSelectionStyleNone) {
        // Handle tap code here
    }
}

End of UITableViewCell selectionStyle example article.