我有一个 UITableView 和一个使用 Swift 的自定义 UITableViewCell。当我设置 self.MyTable.editing = true 时,我看到该行上有删除图标,并且似乎为左侧的重新排序图标添加了空间,但重新排序图标从未显示。
我通过向单元格添加按钮来确认这不是表格的宽度问题。当处于编辑模式时,该按钮被推到左侧,我认为重新排序图标应该在该位置。
我在 UITableView 或 UITableViewCell 的实现中是否遗漏了某些内容?
class MyCell : UITableViewCell
{
var previousState : UITableViewCellStateMask = UITableViewCellStateMask.allZeros
var controller:GolfBagViewController! = nil
var editButton : UIButton! = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
// allow reordercontrol to be shown
self.showsReorderControl = true
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var MyTable: UITableView!
var isEditMode = false
func SetEditMode(sender:UIBarButtonItem){
// when set to true, delete icon appears on left but not reorder icon appears
isEditMode = !isEditMode
self.MyTable.editing = isEditMode
}
func tableView(tableView: UITableView!, canMoveRowAtIndexPath indexPath: NSIndexPath!) -> Bool
{
// indicate that this row can be moved
return true;
}
func tableView(tableView: UITableView!, moveRowAtIndexPath sourceIndexPath: NSIndexPath!, toIndexPath destinationIndexPath: NSIndexPath!)
{
// this never called since reorder control does not appear
var neverGetsHere = 1
}
[ OTHER IMPLMENTATION FUNCTIONS NOT SHOWN ]
}
最佳答案
经过多次尝试和错误,我找到了原因。
在我的自定义 UITableViewCell 中,我重写了 willTransitionToState 并忘记调用 super.willTransitionToState(state)
关于uitableview - UITableView 不显示重新排序控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28460374/