Swift creates TableView and implements protocols

Source: Internet
Author: User

////Viewcontroller2.swift//Swift_helloword////Created by Charlie on 15/7/13.//Copyright (c) 2015 Json. All rights reserved.//Import Foundationimport UIKitclassrootviewcontroller:uiviewcontroller,uitableviewdatasource,uitableviewdelegate {//Protocol        varTableview:uitableview? =UITableView (Frame:cgrectzero, Style:UITableViewStyle.Plain); Overridefunc viewdidload () {Configui ()} func Configui () {TableView!. frame = CGRect (x:0Y:0, Width: the, Height:568) Self.view.addSubview (TableView!) TableView!.Delegate=Self tableView!. DataSource = Self//Set up proxy} func Numberofsectionsintableview (Tableview:uitableview)-Int {return Ten} func TableView (Tableview:uitableview, numberofrowsinsection section:int)-Int {return Ten} func TableView (Tableview:uitableview, viewforheaderinsection section:int)UIView? {        varView:uiview = UIView (Frame:cgrect (x:0Y:0, Width: -, Height: -))        varLa =UILabel (frame:view.frame); La.backgroundcolor=Uicolor.greencolor () La.text="(section) + Partition"  //the name of the partitionView.addsubview (LA)returnview; } func TableView (Tableview:uitableview, heightforheaderinsection section:int)-CGFloat {return  +;//the height of each grouping} func TableView (Tableview:uitableview, Cellforrowatindexpath Indexpath:nsindexpath)-UITableViewCell {varCellid:string ="ID"        varCell = Tableview.dequeuereusablecellwithidentifier (cellid) as? UITableViewCell;//? It's optional, but it could be nil.        ifCell = =Nil {cell=UITableViewCell (Style:UITableViewCellStyle.Default, Reuseidentifier:cellid)} cell?. Textlabel?. Text =String (Indexpath.row)returncell!//return cell or nil    }}

Swift creates TableView and implements protocols

Related Article

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.