Ich versuche derzeit, die Zellen eines UITableView durchzuschleifen, um bestimmte UILabels in der zugehörigen ViewController enthalten.Schleife durch einzelne UITableViewCells in UITableView, um Text in Zellen zu bearbeiten
Wie würde ich das machen?
Kontext: Das Array specialBool enthält 6 Boole. Die Indexposition entspricht einem Produkt, das entweder speziell ist oder nicht. Wenn das Bool wahr ist, möchte ich, dass das Label (previousPrice) in dieser bestimmten Produktzelle gestrichen wird ... wenn es falsch ist, sollte das Label normal bleiben.
Dies ist mein Code so weit. Es ist unvollständig:
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
}
Bitte fügen Sie die relevanten Teile des Codes zu Ihrer Frage als Text, nicht als Bild. – JAL