TableView Implementing Headers and footers
UITableView with Var Tableheaderview:uiview? properties and Var Tablefooterview:uiview? properties, you can create a header and footer for the list tableview by assigning a value to it. Below: The code is as follows:
1 Import UIKit2 3 classViewcontroller:uiviewcontroller,uitableviewdelegate,4 Uitableviewdatasource,uigesturerecognizerdelegate {5 6var tableview:uitableview?7 8var ctrlnames:[string] = ["UILabel Label","UIButton Button","Uidatepiker Date Selector"]9 Ten Overridefunc viewdidload () { One super.viewdidload () A - //Create a table view -Self.tableview =UITableView (Frame:UIScreen.mainScreen (). Applicationframe, the Style:UITableViewStyle.Plain) -self.tableview!.Delegate= Self -self.tableview!. DataSource = Self - //to create a reusable cell +self.tableview!. RegisterClass (Uitableviewcell.self, Forcellreuseidentifier:"Swiftcell") -Self.view.addSubview (self.tableview!) + A //Add header headers to TableView atvar Headerview:uiview = UIView (Frame:cgrectmake (0,0, tableview!. Frame.size.width, -)) -var Headerlabel:uilabel =UILabel (frame:headerView.bounds) -Headerlabel.textcolor =Uicolor.whitecolor () -Headerlabel.backgroundcolor =Uicolor.clearcolor () -Headerlabel.font = Uifont.systemfontofsize ( -) -Headerlabel.text ="TableView Header" in Headerview.addsubview (Headerlabel) -Headerview.backgroundcolor =Uicolor.blackcolor () toTableView?. Tableheaderview =Headerview + - //Add header footer to TableView thevar Footerview:uiview = UIView (Frame:cgrectmake (0,0, tableview!. Frame.size.width, -)) *var Footerlabel:uilabel =UILabel (frame:footerView.bounds) $Footerlabel.textcolor =Uicolor.whitecolor ()Panax NotoginsengFooterlabel.backgroundcolor =Uicolor.clearcolor () -Footerlabel.font = Uifont.systemfontofsize ( -) theFooterlabel.text ="TableView Header" + Footerview.addsubview (Footerlabel) AFooterview.backgroundcolor =Uicolor.blackcolor () theTableView?. Tablefooterview =Footerview + } - $ //in this case, there is only one partition $Func Numberofsectionsintableview (tableview:uitableview!)Int { - return 1; - } the - //returns the number of table rows (that is, the number of returned controls)WuyiFunc TableView (Tableview:uitableview, numberofrowsinsection section:int)Int { the returnSelf.ctrlnames.count - } Wu - //Create individual cell display content (create the cell specified by the parameter Indexpath) About func TableView (Tableview:uitableview, Cellforrowatindexpath Indexpath:nsindexpath) $-UITableViewCell - { - //to provide tabular display performance, the units that have been created must be reused -Let identify:string ="Swiftcell" A //duplicate cells in the same form, registered at the time of declaration +Let cell =Tableview.dequeuereusablecellwithidentifier (Identify, Forindexpath:indexpath) the asUITableViewCell -Cell.accessorytype =Uitableviewcellaccessorytype.disclosureindicator $Cell.textlabel?. Text =Self.ctrlnames[indexpath.row] the returnCell the } the}
iOS development--ui_swift &tableview implementing headers and footers