【发布时间】:2016-05-07 05:47:31
【问题描述】:
我有一个带有 TableView 的 ViewController。 tableView 单元格有一个 StackView,里面有两张图片,外面有一个标签。
在tableView:cellForRowAtIndexPath 中,我得到了单元格,我的数据在arrayList 中。这就是我所做的:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "NamesTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! NamesTableViewCell
let _name = _Names[indexPath.row]
if indexPath.row % 2 != 0 {
cell.backgroundColor = UIColor(hexString: "ededed")
}
cell.labelName.text = _name.name
if _name.gender! == "M" {
cell.pinkCircleImageView.hidden = true
} else if _name.gender! == "F" {
cell.blueCircleImageView.hidden = true
}
return cell
}
如您所见,我会根据名称的性别隐藏图像,并更改每个其他单元格的背景。
现在,我看到的行为是:
https://gyazo.com/1b2d39696892b7fb2f15b71696d9a925
我检查了每个对象的性别。
你们怎么看?谢谢!
【问题讨论】:
标签: ios swift uitableview