The IOS table selectRow method selects cell and does not trigger the didSelectRowAt method

class MainViewController: UIViewController {
    public var seletedIndex: Int = 0
    lazy var tableView: UITableView = {
        let table = UITableView()
        table.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
        return table
    }()
    private var btn: UIButton = {
        let btn = UIButton()
        btn.setTitle("", for: .normal)
        btn.setTitleColor(UIColor.black, for: .normal)
        return btn
    }()
    public var items = [PayMenmet(name: "", icon: "alipay"),PayMenmet(name: "", icon: "wechatpay")]
    lazy var mainView: MainView = MainView()
    private let disposeBag = DisposeBag()
    lazy var service: MainService = MainService.instance
    override func viewDidLoad() {
        super.viewDidLoad()
        initView()
        initBindData()
    }
    func initView() {
        self.view.addSubview(tableView)
        self.view.addSubview(btn)
        tableView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.right.equalToSuperview()
            make.height.equalTo(120)
        }
        btn.snp.makeConstraints { make in
            make.top.equalTo(tableView.snp.bottom).offset(10)
            make.left.right.equalToSuperview().offset(20)
        }
    }
    func initBindData() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.selectRow(at: IndexPath(row: seletedIndex, section: 0), animated: true, scrollPosition: .none)
        btn.rx.tap.subscribe(onNext: { [weak self] in

        })
    }
}
extension MainViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell
        cell.textLabel?.text = items[indexPath.row].name
        cell.imageView?.image = UIImage(named: items[indexPath.row].icon)
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("indexPath::",indexPath)
        let cell = self.tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .checkmark
    }
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        let cell = self.tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .none
    }
}

the result is that although the first row is selected, the didSelectRowAt is not executed, so the accessoryType does not take effect. What is the reason for this?

clipboard.png

clipboard.png

Nov.13,2021

all the shadows selected have come out, and the agent has not left. Is it possible that the proxy set at this time is nil?
I want to implement apple. Now that the agent has been selected, will it be time for him to leave [self.delegate didsele.] if the agent does not leave? Self.delegate is nil


all the actions triggered by the program will not send action, otherwise it is not easy to loop.
just as you set button.selected = YES and do not follow its click events


official API
/ / Selects and deselects rows. These methods will not call the delegate methods (- tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath:), nor will it send out a notification.

  • (void) selectRowAtIndexPath: (nullable NSIndexPath *) indexPath animated: (BOOL) animated scrollPosition: (UITableViewScrollPosition) scrollPosition;
  • (void) deselectRowAtIndexPath: (NSIndexPath *) indexPath animated: (BOOL) animated;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46721-59c03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46721-59c03.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?