Single-selection control styles in Swift UITableViewCell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.