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