不是重複:
問題/答案是關於更改顏色。我改變單元格的顏色沒有問題,相反我有一個問題,當「顏色」.clear
和插入單元格時,單元格正在「重置」。單元格backgroundColor在插入一行時清除奇怪的行爲
每當我將我的單元格的背景顏色設置爲.clear
並在表格中插入一行時,單元格會自動「重置」爲其原始狀態。當背景顏色具有值時不會發生這種情況。
例如:
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
let gesture = UIPanGestureRecognizer()
gesture.addTarget(self, action: #selector(handlePan))
gesture.delegate = self
addGestureRecognizer(gesture)
backgroundColor = .clear
}
func handlePan(_ recognizer: UIPanGestureRecognizer) {
if recognizer.state == .changed {
let translation = recognizer.translation(in: self).x
contentView.frame.origin.x += translation
recognizer.setTranslation(.zero, in: self)
}
if recognizer.state == .ended {
guard let index = delegate?.tableView.indexPath(for: self) else { return }
delegate?.insert(index)
}
}
我的ViewController:
func insert(_ index: IndexPath) {
let cell = tableView.cellForRow(at: index) as? PannableCell
items.append("some")
let path = IndexPath(row: index.row + 1, section: index.section)
tableView.insertRows(at: [path], with: .fade)
}
問:
如何設置我的我的手機的背景色爲.clear
和插入行無細胞是重啓?我想要這個,因爲插入單元格後,我想將原始單元格恢復到原始位置。
編輯:
設置的backgroundColor
顏色只適用於iOS的9在iOS系統10仍然以某種方式重置電池..
可能重複[UITableViewCell顯示白色背景,無法在iOS7上修改](http://stackoverflow.com/questions/18878258/uitableviewcell-show-white-background-and-cannot-be-modified-on-ios7 ) – kevin
感謝您的好鏈接。雖然它不能解決問題,但我希望顏色爲'.clear'時,如果我使用其他顏色(我使用我的表格的背景顏色作爲臨時修訂),它會這樣做。 –
奇怪的是,如果我將'backgroundColor'更改爲另一種顏色(例如:'.gray'),則單元格仍然會重置(插入新單元格),直到單元格被重用爲止。在鏈接kkoltzau提供的答案提供了固定的(當顏色不是'.clear'。 –