您的位置:首页 > 移动开发 > Swift

iOS TableView 使用(swift)

2015-01-07 01:26 543 查看
1.Controller要实现UITableViewDelegate,UITableViewDataSource

class ViewController:UIViewController ,UITableViewDelegate,UITableViewDataSource

2.要将dataSource,delegate设置妥当

myTableView.dataSource =
self
myTableView.delegate =
self

3.完成delegate中的方法
//

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

return datas.count
}

//"cell"为TableViewCell的Identifier

func tableView(tableView:
UITableView, cellForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCell
{
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell")
as
UITableViewCell

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

return cell
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: