How to Set UITableViewCellStyleSubtitle and dequeueReusableCell in Swift?

前端 未结 13 1023
攒了一身酷
攒了一身酷 2020-12-01 05:03

I\'d like a UITableView with subtitle-style cells that use dequeueReusableCellWithIdentifier.

My original Objective-C code was

13条回答
  •  悲&欢浪女
    2020-12-01 05:40

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let reuseIdentifier = "cell"
        var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as UITableViewCell?
        if (cell == nil) {
            cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
        }
        cell!.textLabel?.text = self.items[indexPath.row]
        cell!.detailTextLabel?.text = self.items[indexPath.row]
        return cell!
    }
    

提交回复
热议问题