I looked for a night on the internet yesterday, but most of them are OC Grammar, swift information is too little, so that I just get the introduction of Swift color brushes, the back has been a variety of data, finally let me find
Visiblecells This method, directly paste the code:
My train of thought is this:
1. First get all the cells and traverse the style of the cancel tick.
2. Set the style of the currently selected cell.
Gets the path of the cell that will be selected
func TableView (Tableview:uitableview, Didselectrowatindexpath indexpath:nsindexpath) {
Uncheck the Style
Tableview.deselectrowatindexpath (Indexpath, animated:true);
Gets the currently selected cell
var cell:uitableviewcell!=tableview.cellforrowatindexpath (Indexpath);
Return all cells
Traversal cancels all cell styles
var arry=tableview.visiblecells ();
for (Var i=0;i<arry.count;i++) {
var cells:uitableviewcell=arry[i] As! UITableViewCell;
Cells.accessorytype=uitableviewcellaccessorytype.none
}
Set the selected cell style
Cell.accessorytype=uitableviewcellaccessorytype.checkmark;
}
Run as:
Anyway, I think that learning swift learning for nearly 2 months, and still learning one side of the field to write the project, on the personal feel, this logic is too important, it seems that these soft knowledge to a lot of mending.
PS: There is no place to write the wrong, please spray me, do not skimp on your literary talent, I am proud of the color pens!
Single-selection control styles in Swift UITableViewCell