【发布时间】:2014-11-05 18:19:48
【问题描述】:
大家好,提前感谢你们,我是 Interface builder 和 Swift 的新手,所以它可能是一种或多种技术的组合。
我要做的是一个简单的 UIView,它在界面构建器中包含一个 UITableView,并将它链接到我在 swift 中创建的 viewController。我得到的错误是休闲: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
我相信问题是因为我在 UIViewController 上调用 numberOfRowsInSection 而不是我的类 SearchesMainViewController。
SearchesMainViewController.swift 看起来像这样:
import Foundation
import UIKit
class SearchesMainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var contentTableView: UITableView?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = contentTableView?.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
}
这是我在我的 xib 上为 File's Owner 建立的价值观和联系
再次感谢您的宝贵时间和帮助,我真的很感激 :)
编辑 这就是我在 AppDelegate.swift 中初始化 SearchesMainView 的方式
【问题讨论】:
标签: ios iphone uitableview swift interface-builder