Swift_ uitableview使用自定义cell

和自甴很熟 提交于 2019-12-03 16:43:28

uitableview 使用 xib 的自定义cell 

新建cell:(假如命名 MyCell)

使用:

向 tableview 注册 nib

全局变量 let cellIdentifier = "myCell"

myTableView!.registerNib(UINib(nibName: "MyCell", bundle:nil), forCellReuseIdentifier: cellIdentifier)

然后在 cellForRowAtIndexPath 方法中使用:

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

        // 系统 cell 的简单用法

        //let cell = UITableViewCell(style:.Default, reuseIdentifier:"myCell")

        //cell.textLabel.text = "swift cell \(indexPath.row)"

           

        var mycell : MyCell = tableView!.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as MyCell

        return mycell

    }




标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!