"Fine" form (UITableView) Summary (1): Introduction and basic implementation

Source: Internet
Author: User

reprint Please declare source: http://blog.csdn.net/jinnchang/article/details/45028267
1. Table View (UITableView)UITableView inherits from Uiscrollview. A table view can consist of multiple segments (sections), each of which can have a header and a tail. In many cases, the table view has only one segment, and does not show the tail and Kinsoku. The table view itself can also have a header (shown before the first segment) and one tail (shown after the last fragment). The overall element structure of a table view is as follows:

(1) Table view style

UITableView has the following two styles (Uitableviewstyle)

    • Plain (Normal style)

    • Grouped (group style)

There is no difference between the two styles, only the display style is different.

(2) Table View Split Line (Separator)

The split line has the following three styles (Uitableviewcellseparatorstyle)

    • None (no split line)

    • Singleline (single line)

    • Singlelineetched (line with embossed effect)

(3) Table view cell (cell)

The Cell has the following four kinds of display styles (Uitableviewcellstyle)

    • Default (Textlabel is displayed on the left, Detailtextlabel is not displayed, the leftmost option is ImageView)

    • Value1 (display Textlabel on the left, Detailtextlabel on the right, ImageView on the left)

    • Value2 (the left side shows Textlabel, Detailtextlabel, and the leftmost option shows ImageView)

    • Subtitle (show Textlabel on the left, Detailtextlabel on the left and ImageView on the left)

The Cell has the following four selection styles (Uitableviewcellselectionstyle)

    • None

    • Blue

    • Gray

    • Default

(4) attached graphic (accessory)

The accessory of the cell has the following five styles (Uitableviewcellaccessorytype)

    • None (no attached graphic)

    • Disclosureindicator (small arrow)

    • Detaildisclosurebutton (Details button + arrow pointing to the right)

    • Checkmark (tick)

    • Detailbutton (More Info button)

2. UITableView AgreementIOS follows the MVC design paradigm, where many operations are communicated through agents and the outside world, and UITableView implements the following two types of protocols:
    • Uitableviewdelegate
    • Uitableviewdatasource
The following are the official descriptions of the two agreements, respectively:
Uitableviewdelegate has no required methods. It declares methods The delegate to modify visible aspects of the table view, manage selections, and support an ACC Essory view, and support editing of individual rows in a table.
Uitableviewdatasource has a required methods. The "Numberofrowsinsection" method tells the table view how many rows to display in each section, and the "Cellforrowatind Expath "method provides the cell to display for each row in the table. Optional methods allow the data source to configure multiple sections, provide headers and/or footers, and support adding, removing, and reordering rows in the table.
3. Table View Controller (Uitableviewcontroller)Many times a uiviewcontroller only a uitableview, so Apple official to facilitate the development of a direct supply of a uitableviewcontroller, the controller implemented UITableView data source and proxy protocol, Internally, a TableView attribute is defined for external access, while the entire screen is automatically covered and automatically scaled to facilitate our development. If you need to use a Table View that is not full-screen, we should use Uiviewcontroller to create and maintain uitableview ourselves.
On a certain level, the table view controller has no other advantages than the convenience, automatic provisioning of delegates and data source properties.
4. UITableView Basic Example
viewcontroller.swift//uitableviewsample-basic////Created by Jinnchang on 15/4/12.//Copyright (c) 2015 Jinn Ch Ang.        All rights Reserved.//import Uikitclass Viewcontroller:uiviewcontroller, uitableviewdelegate, UITableViewDataSource {    var tableview:uitableview! Override Func Viewdidload () {super.viewdidload ()//Do any additional setup after loading the view, typical                Ly from a nib. TableView = UITableView (frame:cgrectmake (0, 0, Self.view.frame.size.width, self.view.frame.size.height), style:. Plain) Tableview.registerclass (uitableviewcell.self, Forcellreuseidentifier: "cell") tableview.delegate = SE LF Tableview.datasource = self Self.view.addSubview (tableView)} override func Didreceivememor    Ywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreated. } func TableView (Tableview:uitableview, Numberofrowsinsection section:int), Int {return} func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UIT Ableviewcell {Let cell = Tableview.dequeuereusablecellwithidentifier ("cell", Forindexpath:indexpath) as UITableVi Ewcell Cell.textlabel? Text = "\ (indexpath.row)" Return Cell}}
Project on GitHub address: Https://github.com/jinnchang/SwiftSamples/tree/master/advanced/UITableViewSample-Basic
5. Conclusion

The resources are as follows:

About Table views in IOS Apps

UITableView Class Reference

article last updated: April 13, 2015 16:43:52

"Fine" form (UITableView) Summary (1): Introduction and basic implementation

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.