The implementation of the Swift development iOS app (1) List _php tutorial

Source: Internet
Author: User

Implementation of the list of Swift development iOS apps (1)


Hardware and Software Environment

    • OS X EI Capitan
    • Xcode 7.0.1

Brief introduction

list, which can be said to be the most important one in the control, is UITableView in iOS, and this section will learn how to implement a list, as shown below

Implementation steps

UI section

Create a new project, project named Uitableviewdemo, template select Single View

In the lower-right corner of Xcode, select Table View in the control Library, drag-and-drop to storyboard, and drag it to full screen

Set the table view's prototype cells to 1, then select prototype cells, select Basic in the property attempt in the upper-right corner, stype the identifier to the cell (which can be used in any of the following code files),

Binding data to a list

After the above operation, you can already see the list, but each cell is empty, no data

A color array is provided here, and each of its elements is displayed in the corresponding cell

There is a need to implement the Uitableviewdatasource and uitableviewdelegate two protocols in the Viewcontroller class, and then 2 methods need to be implemented

Func TableView (Tableview:uitableview, Numberofrowsinsection section:int), Int {        return colors.count    

This returns the size of the given array, which is how many rows are in the entire list

Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {let        Cell = Tableview.dequeuereusablecellwithidentifier ("cell", Forindexpath:indexpath)        Cell.textlabel?. Text = Colors[indexpath.row]        return cell    

The "Cell" above is the identifier in storyboard, which returns a string of characters on a cell,cell. The Dequeuereusablecellwithidentifier method reuses cells to improve efficiency and conserve resources. A common list of messages like Weibo, each screen of the device displays only a few messages, a drop-down refresh, a cell or a few, but the content is refilled.

In the final step, switch to storyboard, open the View controller Scene, bind the table view to the view controller, control-Drag the table view to the view Controller on release, select DataSource, repeat once, select delegate

At this point, the data for the list is displayed correctly and can be viewed on the emulator

SOURCE download

Https://github.com/djstava/SwiftForiOS/tree/master/TableViewDemo

http://www.bkjia.com/PHPjc/1103188.html www.bkjia.com true http://www.bkjia.com/PHPjc/1103188.html techarticle The implementation of the Swift development iOS application (1) List of hardware and software environments OS X EI Capitan Xcode 7.0.1 Introduction list, can be said to be the most important one in the control, in iOS is UITableView, this section to learn ...

  • 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.