kiw*_*e89 1 selector uiviewcontroller ios swift
我对Swift非常陌生,因为几个月前我才刚开始使用它。我有这个错误的痛苦的问题。
-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance XXX
Run Code Online (Sandbox Code Playgroud)
这是到目前为止我已经收集和实施的可能的修复程序的列表。
CheckboxQuestion类而不是UIViewController类。 我已经将tableview连接到数据源和委托。
我已经考虑了所有宽松的参考渠道。
我已经为每个原型单元命名了可重用的标识符出口。
毕竟,我仍然收到上面的错误。
这行的appdelegate类中发生了异常错误的断点
class AppDelegate: UIResponder, UIApplicationDelegate {
Run Code Online (Sandbox Code Playgroud)
还有其他我想念的东西吗?
这是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.
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
请确保您已从代码中删除了出口,而不是从Storyboard中删除了。只需从Storyboard中右键单击tableview即可。删除出口并重新连接。可能是您为同一tableview添加了两个出口。
| 归档时间: |
|
| 查看次数: |
5444 次 |
| 最近记录: |