为了账号安全,请及时绑定邮箱和手机立即绑定

swift 中三种创建UITableView的方法和之间的区别

swift 中三种创建UITableView的方法和之间的区别

阿波罗的战车 2019-03-14 10:10:11
swift 中三种创建UITableView的方法和之间的区别
查看完整描述

2 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

UITableView其它一些东西在这里不多讲,这里的就是讲解UITableView的创建。

UITableView的创建有三种方法分别是纯代码、XIB、storyboard。下面就是创建的代码

1.纯代码的创建

首先实例化UITableView(我所有的创建都是在UIViewController类中完成的)

lettableView =UITableView(frame:UIScreen.mainScreen().bounds, style:UITableViewStyle.Plain)
tableView.delegate=self

tableView.dataSource=self

self.view.addSubview(tableView)

必要的几个代理方法

func numberOfSectionsInTableView(tableView:UITableView) ->Int{

return1

}

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

return3

}

这一块是自定义cell

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

letcell=TYCodeTableViewCell.codeTableViewCell(tableView)as!TYCodeTableViewCell

returncell

}

下面是具体用纯代码创建cell

class



查看完整回答
反对 回复 2019-03-22
?
烙印99

TA贡献1829条经验 获得超13个赞

UITableView其它一些东西在这里不多讲,这里的就是讲解UITableView的创建。 UITableView的创建有三种方法分别是纯代码、XIB、storyboard。下面就是创建的代码 1.纯代码的创建 首先实例化UITableView(我所有的创建都是在UIViewController类中完成.

查看完整回答
反对 回复 2019-03-22
  • 2 回答
  • 0 关注
  • 1204 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信