2015-02-11 57 views
0

我有一个UITableView与自定义UITableViewCell使用Swift。当我设置self.MyTable.editing = true时,我看到行中的删除图标,它似乎为左边的重新排序图标增加了空间,但重新排序图标从不显示。重新排序控制不显示UITableView

我通过向单元添加一个按钮来确认它不是宽度问题。在编辑模式下,按钮被推到左边,我假定重新排序图标应该是。

我在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 ] 


} 
+0

澄清:似乎在重排图标的右侧* * – billd 2015-02-11 17:16:58

回答

1

经过多次试验和错误,我找到了原因。

在我的自定义的UITableViewCell我重写willTransitionToState,忘了叫super.willTransitionToState(州)

+0

增加空间,我不能足够给予好评这个答案。我有同样的问题,并忘记在我的重写函数中调用super.layoutSubviews()。当重写一个函数时,总是使用超级,人们! – Audioy 2015-07-02 11:52:26