处于编辑模式时的 UITableViewCell 宽度问题

UITableViewCell Width Issue while in editing mode

我正在使用 UITableview 开发拖动或重新排序列表视图。我没有为此使用情节提要并执行整个功能 programmatically.Draging 功能正常,但 UITableViewCell 根据屏幕截图中的附件在其左侧和右侧放置空白 Space。那么如何删除这个空白 space。只有当我们以编程方式执行此操作时才会出现此问题,如果我们为此使用情节提要,则 uitableviewcell 不会放置任何空白 space.

class ArrangeBinaryViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

// MARK: - Attributes -
var tblTest : UITableView!
var arrTest : [String] = []

// MARK: - Lifecycle -
init(){
    super.init(nibName: nil, bundle: nil)
    self.loadViewControls()
    self.setViewlayout()
}

required init?(coder aDecoder: NSCoder)
{
    super.init(coder:aDecoder)
    self.loadViewControls()
    self.setViewlayout()
}

override func viewDidLoad()
{
    super.viewDidLoad()

    tblTest.setEditing(true, animated: true)
    // Do any additional setup after loading the view.
}

deinit{

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Layout -
func loadViewControls()
{
    arrTest.append("he Table View Controller has an editing mode, when enabled the rows can be reordered by dragging the cells up/down. In this tutorial we will fill the Table View with some data and put the Table View Controller in editing mode. This tutorial is built in iOS 8.1 and Xcode 6.1.")

    arrTest .append("Open Xcode and create a new Single View Application. For product name, use IOS8SwiftReorderingRowsTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.")

    arrTest .append("Remove the View Controller from the Storyboard and drag a Navigation Controller to the empty canvas. When the initial View Controller is deleted there isn't a starting point defined. Select the Navigation Controller and go to the Attribute Inspector. In the View Controller Section  elect the Is Initial View Controller checkbox.")

    arrTest .append("Double-click on the Navigation Bar in The Table View Controller and set the title to Numbers.  Select the Table View Cell and go to the Attributes Inspector. In the Table View Cell section set the Identifier  to Cell.")

    tblTest = UITableView(frame: CGRect.zero, style: UITableViewStyle.grouped)
    tblTest.backgroundColor = UIColor.brown
    tblTest.contentMode = .scaleToFill
    tblTest.delegate = self
    tblTest.dataSource = self
    tblTest.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    tblTest.translatesAutoresizingMaskIntoConstraints = false
    self.view .addSubview(tblTest)
}

func setViewlayout() {

    tblTest.expandIn(SuperView: self.view)

    self.view .addConstraint(NSLayoutConstraint(item: tblTest, attribute: .width, relatedBy: .equal, toItem: self.view, attribute: .width, multiplier: 1.0, constant: 0.0))
    self.view .addConstraint(NSLayoutConstraint(item: tblTest, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 1.0, constant: 0.0))
    self.view .addConstraint(NSLayoutConstraint(item: tblTest, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1.0, constant: 0.0))
    self.view .addConstraint(NSLayoutConstraint(item: tblTest, attribute: .centerY, relatedBy: .equal, toItem: self.view, attribute: .centerY, multiplier: 1.0, constant: 0.0))

    self.view.layoutIfNeeded()
}

// MARK: - Public Interface -


// MARK: - User Interaction -


// MARK: - Internal Helpers -


// MARK: - Delegate Method -
func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return arrTest.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    var cell : UITableViewCell!
    cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

    cell.textLabel?.text = arrTest[indexPath.row]
    cell.textLabel?.numberOfLines = 0
    cell.showsReorderControl = true

    return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 50.0
}

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    print("indexPath",indexPath.row)
    return true
}

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

}

func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {

    if sourceIndexPath.section == proposedDestinationIndexPath.section{
        return proposedDestinationIndexPath
    }
    return sourceIndexPath
}

// MARK: - Server Request -




/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

func loadViewControls()

    tblTest.cellLayoutMarginsFollowReadableWidth = false