我在 Swift Xcode 6.1 中为 UITableView 编写简单代码时遇到以下错误
/Users/classic/Documents/CIPL/Demo Projects/DemoTableView/DemoTableView/ViewController.swift:11:1: Type 'ViewController' does not conform to protocol 'UITableViewDataSource'
/Users/classic/Documents/CIPL/Demo Projects/DemoTableView/UIKit.UITableViewDataSource:3:48: Protocol requires function 'tableView(_:cellForRowAtIndexPath:)' with type '(UITableView, cellForRowAtIndexPath: NSIndexPath) -> UITableViewCell'
有人知道为什么会出现这个问题吗?
最佳答案
您是否在您的类中声明了 UITableVIewDataSource 协议(protocol)的强制函数?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
关于iphone - UITableViewController 委托(delegate)在 swift 中给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27145017/