billd
billd

Reputation: 95

Reorder control does not show for UITableView

I have a UITableView with a custom UITableViewCell using Swift. When I set self.MyTable.editing = true, I see the delete icon on the row and it appears to add space for the reorder icon on the left, but the reorder icon is never shown.

I confirmed it is not a width problem with the table by adding a button to the cell. When in edit mode, the button gets pushed to the left where I assume the reorder icon should be.

Am I missing something in implementation in either the UITableView or 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 ]


}

Upvotes: 0

Views: 1589

Answers (2)

Christian Burke
Christian Burke

Reputation: 1

If you're overriding layoutSubviews() make sure you call layout subviews on the superclass.

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

Upvotes: 0

billd
billd

Reputation: 95

After much trial and error I found the cause.

In my custom UITableViewCell I was overriding willTransitionToState and forgot to call super.willTransitionToState(state)

Upvotes: 1

Related Questions