swift-UItableView


classViewController:UIViewController,UITableViewDataSource,UITableViewDelegate{

vardataTable:UITableView!;

varitemString = ["昵称","账号","性别","地区","我的爱车"]

varscreenObject=UIScreen.mainScreen().bounds;

overridefuncviewDidLoad() {

super.viewDidLoad()

self.title="表格测试"

self.view.backgroundColor=UIColor.lightGrayColor()

creatTable()

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

funccreatTable(){

letdataTableW:CGFloat=screenObject.width;

letdataTableH:CGFloat=screenObject.height;

letdataTableX:CGFloat=0;

letdataTableY:CGFloat=0;

dataTable=UITableView(frame:CGRectMake(dataTableX, dataTableY, dataTableW, dataTableH),style:UITableViewStyle.Grouped);

dataTable.delegate=self

dataTable.dataSource=self

self.view.addSubview(dataTable);

}

functableView(tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

ifsection ==0{

return2;

}else{

return5;

}

}

funcnumberOfSectionsInTableView(tableView:UITableView) ->Int{

return2;

}

functableView(tableView:UITableView, heightForHeaderInSection section:Int) ->CGFloat{

return10;

}

//1.5每组的底部高度

functableView(tableView:UITableView, heightForFooterInSection section:Int) ->CGFloat{

return1;

}

functableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) ->UITableViewCell{

letidentifier="identtifier";

varcell=tableView.dequeueReusableCellWithIdentifier(identifier);

if(cell ==nil){

cell =UITableViewCell(style:UITableViewCellStyle.Value1,reuseIdentifier: identifier);

}

ifindexPath.row==0{

cell?.textLabel?.text="测试"

}else

{

cell?.textLabel?.text=itemString[indexPath.row]

}

returncell!;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容