How can I disable the selection effect when s开发者_运维知识库electing a particular UITableViewCell
?
in tableView:cellForRowAtIndexPath:
method
use this
cell.selectionStyle = UITableViewCellSelectionStyleNone
Swift 3.0
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath) as! UITableViewCell
cell.selectionStyle = .none
return cell
}
The job is done by setting:
cell.selectionStyle = .none
In Swift 4.5/5.0
cell.selectionStyle = UITableViewCell.SelectionStyle.none
Or,
cell.selectionStyle = .none
There a delegate method to setselectionstyle to none.Once this is set reloading the table gives the desired effect.
you can use:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
you can use cell.selectionStyle = UITableViewCellSelectionStyleNone;
or
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
in cellForRowAtIndexPath dataSource method
Write this in didSelectRowAtIndexPath:index
method,
cell.selectionStyle = UITableViewCellSelectionStyleNone
OR
[self.tblName deselectRowAtIndexPath:indexPath animated:NO];
Also you can use this one:
UITableViewCell.appearance().selectionStyle = .none
Consider this behavior for other tableviews in your app.
精彩评论