Swift_ui_uitableview of the iOS development series

Source: Internet
Author: User

Import UIKit

Class Viewcontroller:uiviewcontroller, Uitableviewdatasource, uitableviewdelegate{

var exampletable:uitableview!

var dataarr:nsmutablearray!

var dataarrsection:nsmutablearray!

Override Func Viewdidload () {

Super.viewdidload ()

Self.dataarr = Nsmutablearray.init (capacity:0)

Self.dataarrsection = Nsmutablearray.init (capacity:0)

For I in 0..<34 {

Self.dataArr.addObject ("section \ (i) cell")

Self.dataArrSection.addObject ("section \ (i)")

}

self.exampletable = UITableView (Frame:cgrectmake (0, Uiscreen.mainscreen (). Bounds.width, UIScreen.mainScreen (). BOUNDS.HEIGHT-64)

, style:UITableViewStyle.Grouped)

Self.exampleTable.dataSource = Self

Self.exampleTable.delegate = Self

Self.exampleTable.rowHeight = 55

Self.view. Addsubview (self.exampletable)

Additional setup after loading the view, typically from a nib.

}

Func TableView (Tableview:uitableview, Numberofrowsinsection section:int), Int {

Return 34

}

Func Numberofsectionsintableview (Tableview:uitableview), Int {

Return 10

}

Func TableView (Tableview:uitableview, Titleforheaderinsection section:int), String? {

Return self.dataarrsection[section] as? String

}

Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {

Let identify:string = "Dongfeifei"

var cell = Tableview.dequeuereusablecellwithidentifier (Identify)

if cell = = Nil {

Cell = UITableViewCell (Style:UITableViewCellStyle.Subtitle, reuseidentifier:identify)

}

Cell?. Textlabel?. Text = Self.dataarr[indexpath.row] as? String

Return cell!

}

Func TableView (Tableview:uitableview, Didselectrowatindexpath Indexpath:nsindexpath) {

Print ("Section:\ (indexpath.section) row:\ (indexpath.row)")

}

Override Func didreceivememorywarning () {

Super.didreceivememorywarning ()

Dispose of any resources the can be recreated.

}

}

Swift_ui_uitableview of the iOS development series

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.