Saturday, June 8, 2013

UITableViewCell setSelectionStyle example in Objective C (iOS).


UITableViewCell setSelectionStyle

The style of selection for a cell.

@property(nonatomic) UITableViewCellSelectionStyle selectionStyle

Discussion of [UITableViewCell setSelectionStyle]
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 setSelectionStyle 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 setSelectionStyle].
In cellForRowAtIndexPath use this code:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

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


UITableViewCell setSelectionStyle example.
All you have to do is set the selection style on the UITableViewCell instance using either:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Further, make sure you either don't implement -tableView:didSelectRowAtIndexPath: in your table view delegate or explicitly exclude the cells you want to have no action if you do implement it.


End of UITableViewCell setSelectionStyle example article.