-[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 [英] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

查看:23
本文介绍了-[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Swift 还很陌生,因为几个月前我才刚刚开始使用它.我有这个错误的痛苦问题.

I am very new to Swift as I justed started on it only a few months back. I have an aching problem with this error.

-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance XXX

以下是我迄今为止收集和实施的可能修复的列表.

Here is a list of possible fixes that I have so far gathered and implemented already.

  1. 我已将自定义类更改为 CheckboxQuestion 类,而不是 UIViewController 类.
  1. I have changed the Custom Class to CheckboxQuestion class instead of the UIViewController class.

自定义类

  1. 我已将 tableview 连接到数据源和委托.

  1. I have connected the tableview to the datasource and delegate.

我已经考虑了所有松散的引用出口.

I have accounted for all loose referencing outlets.

我已经为每个原型单元命名了可重复使用的标识符出口.

I have named the reusable identifier outlet for each prototype cell.

原型单元 1

毕竟,我仍然收到上述错误.

After all those, I am still getting the error above.

appdelegate 类中发生异常错误的断点在这一行

The breakpoint of the exception error happened in the appdelegate class at this line

class AppDelegate: UIResponder, UIApplicationDelegate {

还有什么我遗漏的吗?

这里是CheckboxQuestion类代码的代码

Here is the code for CheckboxQuestion Class code

import UIKit

var checkboxCellInfo = ["Field 1", "Field 2"]

class CheckboxQuestion: UIViewController {

@IBOutlet weak var tableView: UITableView!

//1. determine number of rows of cells to show data
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
    return checkboxCellInfo.count + 1
}

//2. inputs info into each cell from array 'cellInfo'
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell? {

    if indexPath.row <= checkboxCellInfo.count - 1 {

        let cell:CheckboxQuestionCellConnect = self.tableView.dequeueReusableCellWithIdentifier("CheckboxNumber") as! CheckboxQuestionCellConnect

        return cell 

     } else {

        let cell:CheckboxQuestionCellConnect = self.tableView.dequeueReusableCellWithIdentifier("CheckboxAdd") as! CheckboxQuestionCellConnect

        return cell

    }  
}

//3. determines height of each cell
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 60
}

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

推荐答案

请确保您从代码中删除了插座,而不是从故事板中删除.只需右键单击故事板中的表格视图.删除插座并重新连接它.可能您添加了两个插座对于相同的tableview.

please ensure you deleted outlets from code but not from storyboard.just right click on tableview from storyboard .delete outlets and reconnect it.May be you have added two outlets for same tableview.

这篇关于-[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆