Select First Row as default in UITableView

后端 未结 11 1739
悲哀的现实
悲哀的现实 2021-01-30 20:12

I have an application that is viewbased and I am adding a tableview as a subview to the main view. I have taken UITableViewDelegate to respond the table methods.

11条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 20:50

    Swift 5.x Update:

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        let indexPath = IndexPath(row: 0, section: 0)
        tableView.selectRow(at: indexPath, animated: true, scrollPosition: .bottom)
        tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)
    }
    

    This is working for me and hope this will helps you.

    Happy Coding :)

提交回复
热议问题