Import UIKit
Class viewcontroller2:uiviewcontroller,uitableviewdelegate,uitableviewdatasource{
Override Func Viewdidload () {
Super.viewdidload ()
Self.view.backgroundcolor=uicolor.orangecolor ()
var Mytableview = UITableView (frame:cgrectmake (0, 0, UIScreen. Mainscreen (). Bounds.size.width, Uiscreen.mainscreen (). bounds.size.height), Style:UITableViewStyle.Plain)
Self.view.addSubview (Mytableview)
Mytableview.delegate = Self
Mytableview.datasource = Self
Mytableview.backgroundcolor = Uicolor.whitecolor ()
}
Func Numberofsectionsintableview (Tableview:uitableview), Int {
Return 1
}
Func TableView (Tableview:uitableview, Numberofrowsinsection section:int), Int {
Return 10
}
Func TableView (Tableview:uitableview, Heightforrowatindexpath indexpath:nsindexpath), CGFloat {
Return 60
}
Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {
var cell = UITableViewCell ()
Cell.textlabel?. Text = "Myfirstswift"
Cell.detailtextlabel?. Text = "Gaga"
if indexpath.row%2 = = 0{
Cell.imageview?. Image = UIImage (named: "Image1")
}else{
Cell.imageview?. Image = UIImage (named: "Image2")
}
return cell
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift creates TableView and implements protocols