iOS开发中的界面定制与模态对话框使用
1. UITableView数据源协议实现
为了满足 UITableViewDataSource
协议的要求,需要实现两个关键方法。以下是示例代码:
func tableView(_ tv: UITableView, numberOfRowsInSection sec: Int) -> Int {
return self.orig.tableView(tv, numberOfRowsInSection: sec)
}
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.orig.tableView(tableView, cellForRowAt: indexPath)
cell.textLabel!.font = UIFont(name: "GillSans-Bold", size: 14)!
return cell
}
上述代码中, tableView(_:numberOfRowsInSection:)
方法将消息传递给原始数据源,以获取指定分区的行数。 tableView(_:cellForRowAt:)
方法同样先从原始数据源获取单元格,然后将单元格的文本字体修改为 GillSans-Bold