-1

my tableView inside collectionViewCell when i call collectionViewCell.tableview.perforSelector() my app is crash and given below exception.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView DataOnUI]: unrecognized selector sent to instance 0x7ff267876600'

my app is crash on this line: - "self.tblTopics?.perform(Selector("DataOnUI"), on: .main, with: nil, waitUntilDone: true)"

Code:

//****************************************************//
extension SelectedCategoriesCell: UITableViewDataSource, UITableViewDelegate {

    //----------------------------------------------
    func setUpTableView(){
        tblTopics?.rowHeight = UITableView.automaticDimension
        tblTopics?.estimatedRowHeight = 44
        tblTopics?.allowsMultipleSelection = true
        lcHeightOftblTopicsTable?.constant = 0
        setUpTableData()
    }

    //----------------------------------------------
    func setUpTableData(){
        tblTopics?.dataSource = self
        tblTopics?.delegate = self
        self.tblTopics?.reloadData()
        self.tblTopics?.perform(Selector("DataOnUI"), on: .main, with: nil, waitUntilDone: true)

    }

    func DataOnUI() {
        self.lcHeightOftblTopicsTable?.constant = self.tblTopics?.contentSize.height ?? 0
        self.tblTopics?.reloadData()
        self.layoutIfNeeded()
        self.setNeedsDisplay()
    }

    //----------------------------------------------
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return arrayAllTopic?.count ?? 0
    }

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

    //----------------------------------------------
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let cell = tableView.dequeueReusableCell(withIdentifier: TopicsCell.className, for: indexPath) as? TopicsCell {
            if let jsonObject = arrayAllTopic?[indexPath.row] {
                var topicModel = Model.ListAllCategories(json: jsonObject)
                cell.lblTopicTitle?.text = topicModel.name
                return cell
            }
        }
        return UITableViewCell()
    }

    //----------------------------------------------
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        var jsonData = arrayAllTopic?[indexPath.row]
            jsonData?[api.kisSelected] = true
        arrayAllTopic?[indexPath.row] = jsonData!
        print("\(arrayAllTopic)")

    }

    //----------------------------------------------
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
         var jsonData = arrayAllTopic?[indexPath.row]
            jsonData?[api.kisSelected] = false
        arrayAllTopic?[indexPath.row] = jsonData!
        print("\(arrayAllTopic)")
    }


}

Thanks for your suggestion..

  • 1
    `func DataOnUI()` is on `SelectedCategoriesCell`, so shouldn't it be `self.perform(...)` instead, meaning that `self` (which is a `SelectedCategoriesCell`) instance that should perform that method. – Larme Mar 25 '20 at 17:33

1 Answers1

1

First of all, never write out the name of a selector as a string: Selector("DataOnUI"). You don't know how to do it, and even if you do, the compiler knows more than you do. Use #selector syntax: #selector(DataOnUI).

Second, when you do that, the compiler will help you by telling you that func DataOnUI() needs an @objc marking.

Third, do not ever start the name of a func with a capital letter again, just because.

matt
  • 515,959
  • 87
  • 875
  • 1,141