Good Morningxem bảng của tôi tái sử dụng các ô được chọn khi cuộn - trong SWIFT
vấn đề của tôi là xem bảng của tôi tái sử dụng các ô đã chọn khi tôi di chuyển xuống và lên một lần nữa .. tôi có nghĩa là khi tôi chọn một tế bào từ sau đó cuộn xuống, một số ô mà tôi không chọn được hiển thị được chọn, một số ô được chọn không hiển thị được chọn khi tôi cuộn lên lần nữa và khi điều đó xảy ra, tôi lại là táo để chọn nhiều hơn một ô mà không phải cho phép .. tôi muốn đề cập đến rằng tôi đã cố gắng để lưu đường dẫn chỉ mục cũ từ 'didSelectRowAtIndexPath'and tôi đã kiểm tra nó như thế này trong' CellForRowAtIndexPath'but nó không hoạt động:
if (old == indexpath)
{
cell?.backgroundColor = UIColor.redColor()
cell?.textLabel?.backgroundColor = UIColor.whiteColor() //to change only the thumbnail color and keep the cell color
}
else {
cell?.backgroundColor = UIColor.whiteColor()
}
Bây giờ ở đây là mã của tôi
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = myTable.dequeueReusableCellWithIdentifier("WorkCell") as UITableViewCell
cell.tag = (indexPath.row) + 1
cell.textLabel?.text = Berufs[indexPath.row]
var img = UIImageView(frame: CGRect(x: 10, y: 3, width: 40 , height: 40))
cell.selectionStyle = UITableViewCellSelectionStyle.None
img.image = UIImage(named: "transparent.png")
cell.indentationLevel = 1
cell.indentationWidth = 45
cell.addSubview(img)
return cell
}
var old = 1000
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let indexPath = tableView.indexPathForSelectedRow()
let cell = tableView.cellForRowAtIndexPath(indexPath!)
var tmpCell = view.viewWithTag(old)
var rowNum = (cell?.tag)! - 1
if (cell?.backgroundColor == UIColor.redColor())
{
cell?.backgroundColor = UIColor.whiteColor()
}
else if (cell?.backgroundColor != UIColor.redColor())
{
tmpCell?.backgroundColor = UIColor.whiteColor()
cell?.backgroundColor = UIColor.redColor()
cell?.textLabel?.backgroundColor = UIColor.whiteColor()
println("du interssiert dich für \(Berufs[rowNum])")
}
old = rowNum + 1
}
hoạt động như một nét duyên dáng * __ * thankssssssss –
câu trả lời này thật tuyệt vời và hoạt động như một sự quyến rũ, nhưng tại sao bạn lại ghi đè lên trước một số chức năng? miễn là bộ điều khiển thực hiện UITableViewDelegate, bạn chỉ nên có chức năng nhưng không có "ghi đè" phải không? –
cảm ơn U đã tiết kiệm thời gian của tôi quá :) – user1553381