The single-choice control style in swift UITableViewCell and uitableviewcell

Source: Internet
Author: User

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!

 

Related Article

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.