【发布时间】:2020-03-25 17:30:57
【问题描述】:
collectionViewCell 中的我的 tableView 当我调用 collectionViewCell.tableview.perforSelector() 我的应用程序崩溃并出现以下异常。
由于未捕获的异常“NSInvalidArgumentException”而终止应用,原因:“-[UITableView DataOnUI]:无法识别的选择器已发送到实例 0x7ff267876600”
我的应用程序在此行崩溃:- "self.tblTopics?.perform(Selector("DataOnUI"), on: .main, with: nil, waitUntilDone: true)"
代码:
//****************************************************//
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)")
}
}
谢谢你的建议。。
【问题讨论】:
-
func DataOnUI()在SelectedCategoriesCell上,所以不应该是self.perform(...),这意味着应该执行该方法的self(这是一个SelectedCategoriesCell)实例。跨度>
标签: ios swift ios13 swift5 xcode11