美文网首页
UITableView 实现自定义 TableViewCell

UITableView 实现自定义 TableViewCell

作者: ImWiki | 来源:发表于2019-05-27 23:39 被阅读0次

创建一个继承 UITableViewCell 的类

image.png

选择UITableViewController 的 Cell,关联刚刚创建的 UserCell。

image.png

关联 Label 到 UserCell

image.png

为Cell设置Identifier

image.png

实现代码

class HomeTimelineViewController: UITableViewController {

    let users = ["Wiki","Teny","Joy"]
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "userCell"
        let cell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? UserCell
        let item = users[indexPath.row]
        cell?.userLabel.text = item
        return cell!
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return users.count
    }
}

相关文章

网友评论

      本文标题:UITableView 实现自定义 TableViewCell

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