我目前正在嘗試循環遍歷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