Friday, May 10, 2024
HomeiOS Developmentios - UITableView reordering controls aren't exhibiting in UIViewController

ios – UITableView reordering controls aren’t exhibiting in UIViewController


Unsure what’s flawed, I really feel like I’ve accomplished this a thousand occasions through the years, however its not working this time.

I’ve a UIViewController (not UITableViewController) and I create a UITableView in loadView(). I set the delegate and the datasource. I implement the canMoveRowAt and the moveRowAt delegate strategies. I add a UIBarButtonItem to faucet to place the desk into edit mode however not one of the reorder controls present up.

class MyTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var tableview: UITableView!

    override func loadView() {
        // deliberately not calling tremendous
        
        self.tableview = UITableView(body: .zero, model: .grouped)
        self.tableview.delegate = self
        self.tableview.dataSource = self
        self.view = self.tableview
    }
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()

        self.tableview.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        
        let reorderbutton = UIBarButtonItem(picture: UIImage(systemName: "mount"), model: .plain, goal: self, motion: #selector(tappedreorder(_:)))
        
        self.navigationItem.rightBarButtonItems = [reorderbutton]
    }
        
    @objc func tappedreorder(_ sender:Any) {
        self.tableview.setEditing(true, animated: true)
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        var config = cell.defaultContentConfiguration()
        config.textual content = ...
        cell.contentConfiguration = config
        
        return cell
    }
    

    func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        print("moved row from (sourceIndexPath) to (destinationIndexPath)")
    }
    
    func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
        print("can transfer row at (indexPath), true")
        return true
    }
    
}

Once I set the desk into modifying mode, I do not get any calls backs to canMoveRowAt and not one of the rows present the reorder controls.

I’ve additionally tried including cell.showsReorderControl = self.tableview.isEditing to the cellForRowAt implementation in order that it explicitly requests the transfer management, however that did not change something as a result of not one of the rows have been really being reloaded. Even once I set the desk into edit mode after which did a reloadData() to reload all of the rows and set cell.showsReorderControl, they nonetheless did not present up.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments