Swift: CREATE TABLE UITableView

Source: Internet
Author: User

Creating cells with Swift is basically the same as creating cells with iOS, which is somewhat different in syntax. The call member method in Swift no longer uses [] to send a message, but instead uses the form of a. Member method to invoke the member function. This format is very similar to the point member operator in Java. References to other classes in Swift do not have to be imported into the header file. There's no nonsense here, now. The Pure code creation UITableView instance is as follows:

The concrete examples are as follows:

1. First create a project project with Swift

2. Create a person class with swift and generate the Person.swift file

3. Class The properties set in the Perosn.swift file.

4. The table code in the Viewcontroller.swift file is as follows:

Let the Viewcontroller class inherit the data source and proxy protocol, declaring both the array and the table view properties

Initialize the table view, create the data and add it to the array, set up the data source and the proxy, and finally add the table view to the view

Ways to implement a data source protocol

Methods of implementing Proxy protocol

//Demo results are as follows:

Start: When you tap a cell:

When you click a cell again, the previous cell marker is canceled, and the current cell is labeled

Swift: CREATE TABLE UITableView

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.