////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