我目前正在尝试循环遍历UITableView的单元格,以删除相关viewController中包含的特定UILabel。循环遍历UITableView中的单个UITableViewCells以编辑单元格中的文本
我该怎么做呢?
上下文:数组specialBool包含6个布尔值。索引位置对应于特殊或不特定的产品。如果布尔值为true,那么我希望该特定产品单元格中的标签(previousPrice)被删除...如果它为假,那么标签应该保持正常。
这是我的代码到目前为止。这是不完整的:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! exploreTableView
cell.photo.image = globalVariable.images[indexPath.row]
cell.name.text = globalVariable.names[indexPath.row]
cell.price.text = globalVariable.prices[indexPath.row]
cell.unitPrice.text = globalVariable.unitPrice[indexPath.row]
cell.pPrice.text = globalVariable.previousPrice[indexPath.row]
var i = 0
while i < globalVariable.previousPrice.count {
if (globalVariable.specialBool[i] == true) {
// Strike through previous price
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: globalVariable.previousPrice[i])
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))
cell.pPrice.attributedText = attributeString;
} else {
cell.pPrice.text = globalVariable.previousPrice[i]
}
i += 1
}
return cell
}
请将代码的相关部分作为文本添加到您的问题中,而不是图片。 – JAL