這實際上是一個兩部分的問題。首先看一下代碼:
//canEditRowAt
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if tableView.tag == 1000{
return indexPath.row == 0 ? false : true
}
return true
}
//canMoveRowAt
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
if tableView.tag == 1000{
return indexPath.row == 0 ? false : true
}
return true
}
所以從這個我希望它會阻止索引 0 處的行讓其他單元格移動到它,但是沒有......如你所見:

我顯然想阻止它,但似乎找不到任何檔案來解決這個問題。
我正在努力的另一點;如果您查看記錄,您會看到,一旦我將一個單元格移動到任何位置,單元格后面就會出現一個黑條。我也想避免這種情況發生,并且嘗試了幾件事,但沒有任何效果。
任何幫助表示贊賞,謝謝!
uj5u.com熱心網友回復:
要回答第一個問題,如果您查看tableView(_:canMoveRowAt:) 
2.用戶標題視圖
This way you don't have to worry about specify any logic of which cells can move and which cannot as you can have the non movable data in a header view:
override func tableView(_ tableView: UITableView,
viewForHeaderInSection section: Int) -> UIView?
{
if section == 0
{
// Customize any view
let headerView = UIView(frame: CGRect(x: 0,
y: 0,
width: tableView.bounds.width,
height: 100))
headerView.backgroundColor = .red
let label = UILabel(frame: headerView.bounds)
label.text = "Header view"
label.textColor = .white
label.textAlignment = .center
headerView.addSubview(label)
return headerView
}
return nil
}
override func tableView(_ tableView: UITableView,
heightForHeaderInSection section: Int) -> CGFloat
{
if section == 0
{
// specify any height
return 100
}
return 0
}

I recommend the second option as it has the better user experience and seems to be the right way of approaching this problem.
To answer your second question, in your cellForRowAt indexPath or custom cell implementation, you probably set the background view of the cell or the contentView to black.
Try setting one of these or both:
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .clear
This should not give you a black background
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/436876.html
