我正在使用 Xcode7.2.1 iOS9.2 SDK。
- 注册单元笔尖:
代码:
self.TbuserList.registerNib(UINib.init(nibName: "UserCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "idUserList")
- 设置单元格 detailTextLabel 文本:
代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("idUserList",forIndexPath: indexPath ) as! UserCell
//print(self.users)
cell.textLabel?.text = self.users[indexPath.row]["nickname"] as? String
cell.detailTextLabel?.text = (users[indexPath.row]["isConnected"] as! Bool) ? "Online" : "Offline"
cell.detailTextLabel?.textColor = (users[indexPath.row]["isConnected"] as! Bool) ? UIColor.greenColor() : UIColor.redColor()
return cell
}
注意:当我将单元格样式从“右细节”更改为“副标题”或“左细节”时,就可以了。