0

UITableview를 사용하여 끌기 또는 재정렬 목록보기를 개발 중입니다. 나는 이것을 위해 스토리 보드를 사용하지 않고 있으며 프로그래밍 방식으로 전체 기능을 수행하고 있습니다. 기능을 작동하는 중입니다. UITableViewCell 왼쪽과 오른쪽에 빈 공간을 넣는 모습이 스크린 샷에 첨부되어 있습니다. 이 빈 공간을 제거하는 방법. 이 문제는 스토리 보드를 사용하는 경우 프로그래밍 방식으로이 작업을 수행 할 때만 발생하며 uitableviewcell은 빈 공간을 두지 않습니다.UITableViewCell 너비 편집 모드에서 발생하는 문제

클래스 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. 
} 
*/ 

} enter image description here

답변

3

FUNC의 loadViewControls()

tblTest.cellLayoutMarginsFollowReadableWidth = false 
+0

용액으로 작동 – Hiren

관련 문제