The single-choice control style in swift UITableViewCell and uitableviewcell
I found the materials for one night on the internet yesterday, but most of them use the OC syntax. There are too few swift documents, which makes it hard for me to get started with swift, I have been reading various materials and finally found them.
VisibleCells:
My idea is as follows:
1. First retrieve all cells and traverse the unchecked style.
2. Set the style of the currently selected cell.
// Obtain the path of the cell to be selected
Func tableView (tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath ){
// Cancel the selected Style
TableView. deselectRowAtIndexPath (indexPath, animated: true );
// Obtain the currently selected cell
Var cell: UITableViewCell! = TableView. cellForRowAtIndexPath (indexPath );
// Return all cells
// Print and cancel all cell styles
Var arry = tableView. visibleCells ();
For (var I = 0; I <arry. count; I ++ ){
Var cells: UITableViewCell = arry [I]! UITableViewCell;
Cells. accessoryType = UITableViewCellAccessoryType. None
}
// Set the selected cell style
Cell. accessoryType = UITableViewCellAccessoryType. Checkmark;
}
Run as follows:
Anyway, I think I 've been learning swift for almost two months, and I still want to write projects while learning. I personally think this logic is too fucking important, it seems that this soft knowledge should be supplemented.
PS: if something is wrong, Please spray me a lot. Do not be stingy with your literary talents. I am proud to be a colorful pen!