У меня есть MGSwipeTableCell, добавленный в мой tableView следующим образом:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let reuseIdentifier = "Cell"
var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
if cell == nil {
cell = MGSwipeTableCell(style: UITableViewCellStyle.Default, reuseIdentifier: reuseIdentifier)
}
cell.delegate = self
cell.backgroundColor = blue
}
Все работает нормально. Но теперь, если я нажму на ячейку, цвет ячейки изменится, может быть, на секунду на белый, а затем на зеленый (цвет по умолчанию — синий). Вот что должно произойти, если ячейка была нажата:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let mySelectedCell = tableView.cellForRowAtIndexPath(indexPath) as! MGSwipeTableCell!
mySelectedCell.backgroundColor = green
mySelectedCell.detailTextLabel?.text = "Test"
}
Таким образом, цвет должен измениться только на зеленый, а не на белый, а затем на зеленый, и должен отображаться detailTextLabel с текстом «Тест». Я надеюсь, что вы можете помочь мне решить эту проблему. Я действительно не знаю, что делать.
Решение:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let reuseIdentifier = "Cell"
var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as! MGSwipeTableCell!
cell = MGSwipeTableCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.delegate = self
cell.backgroundColor = blue
}
mySelectedCell
объект, который используете вtableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
? - person Alexey Pichukov   schedule 16.11.2015Selection
для вашей пользовательской ячейки вAttributes inspector
в раскадровке? - person Alexey Pichukov   schedule 16.11.2015None
. Похоже, ячейка выбрана, а затем отбрасываете ее. - person Alexey Pichukov   schedule 16.11.2015