
在swift中
使用let 声明常量,仅允许一次赋值,第二次赋值则会出错
使用var声明变量,可以多次进行赋值
!结尾表示该对象不能为空,必须进行初始化才能使用,否则报错
?结尾表示改对象可以为空,直接使用不会报错,
//// VIEwController.swift// SwiftEx//// Created by reylen on 15/11/18.// copyright © 2015年 reylen. All rights reserved.//import UIKitclass VIEwController: UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate { var tableVIEw: UItableVIEw! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw,typically from a nib. self.Title = "Swift Test" self.navigationItem.rightbarbuttonItem = UIbarbuttonItem.init(Title: "WebTest",style: UIbarbuttonItemStyle.Plain,target: self,action: Selector("gotoWebTest")) initUI() } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. } func initUI () { self.tableVIEw = UItableVIEw.init(frame: self.vIEw.bounds,style: UItableVIEwStyle.Plain) self.tableVIEw.delegate = self self.tableVIEw.dataSource = self self.vIEw.addSubvIEw(self.tableVIEw) } // MARK: Action func gotoWebtest(){ let web = WebVIEwController.init(nibname: nil,bundle: nil) self.navigationController?.pushVIEwController(web,animated: true) } // MARK: tableVIEw dataSource,delegate 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 90 } func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell { var cell : UItableVIEwCell!; let IDentifIEr = "cellIDentifIEr" cell = tableVIEw.dequeueReusableCellWithIDentifIEr(IDentifIEr) if(cell == nil) { cell = UItableVIEwCell.init(style: UItableVIEwCellStyle.SubTitle,reuseIDentifIEr: IDentifIEr) } cell.textLabel?.text = String.init(format: "this is row %i",arguments: [indexPath.row]) cell.detailTextLabel?.text = "detail" return cell }}总结
以上是内存溢出为你收集整理的Swift之UITableView的使用全部内容,希望文章能够帮你解决Swift之UITableView的使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)