iphone - UITableViewController 委托(delegate)在 swift 中给出错误

标签 iphone swift

我在 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/

相关文章:

iphone - iTunes 音乐链接

iphone - UIScrollView - 确定滚动停止的位置

iphone - 如何在 UITableView 中激活下一个 UITextField?

iphone - presentationLayer 值在动画期间未更新?

ios - 带有 subview 的性能 UICellView

objective-c - 无法使用 Swift 协议(protocol)将符合协议(protocol)的 Objective-C 类分配给属性

ios - 在文本属性字典中实例化 UIFont 时出错

swift - 如何在 Swift 中过滤对象数组?

iphone - 在 iPhone 上使用 opencv features2d

ios - Cell Swift 中的 UITextView