【问题标题】:Reorder control does not show for UITableViewUITableView 不显示重新排序控件
【发布时间】:2019-05-20 11:25:15
【问题描述】:

我有一个 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 ]


}

【问题讨论】:

  • 澄清:似乎为右侧的重新排序图标添加空间

标签: uitableview swift


【解决方案1】:

经过反复试验,我找到了原因。

在我的自定义 UITableViewCell 中,我覆盖了 willTransitionToState 并忘记调用 super.willTransitionToState(state)

【讨论】:

  • 我不能对这个答案给予足够的支持。我有同样的问题,忘记在我的覆盖函数中调用 super.layoutSubviews() 。人,在重写函数时总是使用 super!
【解决方案2】:

如果您要覆盖 layoutSubviews(),请确保在超类上调用布局子视图。

override func layoutSubview() {
  super.layoutsubviews()
  // custom implementation
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    相关资源
    最近更新 更多