
// 注册nib
tableView.registerNib(UINib(nibName: "nibName", bundle: mainBundle), forCellReuseIdentifier: "cellIdentifier")
// 注册类
tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: "cellIdentifier")
// 数据源
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as! TableViewCell
return cell
}
使用注册类的时候需要手写代码
重写init(style: UITableViewCellStyle, reuseIdentifier: String?)方法,并在里面进行UI设置
ps: 网上搜自定义cell教程还是挺多的
在Xcode中,选择 File\New\Project… 创建一个新项目。选择 Single View Application 点 Next 。将项目命名为 CandySearch 确保 Language 设置为 Swift 并且 Devices 设置为 iPhone 。点击完成,选择你想储存的位置,然后点击 Create 。首先将默认的文件清理掉,这样你就可以真正的从头开始。在 Project Navigator中,选择 ViewController.swift ,右键点击,选择删除,然后选择 Move to Trash 。然后打开 Main.storyboard ,选择唯一的一个view controller然后删掉他。现在你有一个空的storyboard,可以在你的应用中添加主屏幕了。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)