【发布时间】:2016-01-09 10:10:36
【问题描述】:
我对 Swift 很陌生,因为几个月前我才刚刚开始使用它。我对这个错误有一个痛苦的问题。
-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance XXX
这是我迄今为止收集并实施的可能修复的列表。
- 我已将自定义类更改为
CheckboxQuestion类,而不是UIViewController类。
我已将 tableview 连接到数据源和委托。
我已经计算了所有松散的参考出口。
我已经为每个原型单元命名了可重复使用的标识符出口。
在所有这些之后,我仍然收到上述错误。
异常错误的断点发生在这一行的appdelegate类中
class AppDelegate: UIResponder, UIApplicationDelegate {
我还有什么遗漏的吗?
这里是 CheckboxQuestion 类代码的代码
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.
}
}
【问题讨论】:
标签: ios swift uiviewcontroller selector