美文网首页
wift-UItableView

wift-UItableView

作者: 笨的很想飞 | 来源:发表于2016-06-03 11:07 被阅读27次


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!;

}

}

相关文章

网友评论

      本文标题:wift-UItableView

      本文链接:https://www.haomeiwen.com/subject/czygqttx.html