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!;
}
}
网友评论