【发布时间】:2018-02-01 16:46:35
【问题描述】:
问题是当我按下特定 tableViewCell 中的按钮时尝试打开一个新的 VC。 Bellow 是我的 tableView,它正在加载单元格。第 0 部分中的那个是带有按钮的那个。
class NewConversationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
} else if section == 1{
return friendList.count
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "NewGroupConversationCell") as! NewGroupConversationTableViewCell
return cell
} else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "NewConversationCell") as! NewConversationTableViewCell
let friendList = self.friendList[indexPath.row]
cell.populate(friendList)
return cell
}
return UITableViewCell()
}
下面是带有按钮的单元格和将呈现我想要的特定视图控制器的操作
class NewGroupConversationTableViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func groupButtonPressed(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let messagesViewController = storyboard.instantiateViewController(withIdentifier: "GroupListViewController") as! GroupListViewController
self.window?.rootViewController?.present(messagesViewController, animated: true, completion: nil)
}
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[VoiceMe.GroupListViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例 0x7fb33171c4d0”
【问题讨论】:
-
这可能是由于您在连接插座/操作时犯了一个错误。检查它们。
-
实际上我仔细检查了它们并没有任何线索..
-
检查您的网点和数据源/代表是否在您的
GroupListViewController上正确设置。这是UITableViewController吗?错误不在此 VC 的代码中,而是在您推送的代码中。 -
其实 GroupListViewController 是一个 UIViewController 也包括一个 tableViewController
-
所以,毕竟我让它工作了,我必须包括委托和数据源,所以你是对的
标签: ios swift uitableview swift3