开发者

How to make cells in UITableView not turn blue?

I am using a UITableView and the cells I am using in this view should do nothing when I click them. I can't turn off UserInteraction though because then I am not able to click on the accessory (detailDisclosureButton). So how can I make them stop turning blue 开发者_开发技巧and still allow them to click on the accessory?


By default, the selectionStyle property of cell is UITableViewCellSelectionStyleBlue. Change it to UITableViewCellSelectionStyleNone.


When you're generating the UITableViewCell (within the UITableView's - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method call), simply set the selectionStyle property to UITableViewCellSelectionStyleNone.

Set the UITableViewCell Class Reference for more information.


Use the UITabelViewCell selectionStyle property.

myCell.selectionStyle = UITableViewCellSelectionStyleNone;


 tableView.allowsSelection = NO;


You can do this by adding the selection style to none or gray. By default it is blue.

cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleGray;

You need to write this code in the method "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath".


If you want use to select cell add below code in method viewDidLoad

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

moreover you can disable selection overall for your whole table by adding:

self.tableView.allowsSelection = NO;


It can easily done by StoryBoard without writing one line of code. In your UITableViewCell's XIB in Attribute Inspector set value of Selection to Gray or None to stop a cell turning blue on selection and it still be selectable.

How to make cells in UITableView not turn blue?


Programtically Default UITableViewCell is UITableViewCellSelectionStyleBlue Change it UITableViewCellSelectionStyleNone.

myCell.selectionStyle = UITableViewCellSelectionStyleNone;

By using StoryBoard

How to make cells in UITableView not turn blue?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜