iOS development--ui_swift &tableview implementing headers and footers

Source: Internet
Author: User

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

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.