- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
因此,我在 Xcode 中收到“Type ViewController does not conform to protocol UITableViewDataSource”错误。我已经实现了所需的功能:
我什至确定我已经告诉 Xcode 有多少部分(这不是必需的)。这是一个单 View 应用程序,我已确保在 Storyboard 中正确设置了我的引用。所以我的奥特莱斯是我的 View 和我的 TableView 。我的引用 socket 设置为数据源和委托(delegate)是我的 TableView 。
这是代码。
ViewController.swift
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var items: [String] = ["We", "Dislike", "Swift", "Very", "Much", "Right", "Now"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath:indexPath) as UITableViewCell
cell.textLabel?.text = self.items[indexPath.row]
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
}
}
编辑:另外,我知道我不应该需要 tableView.delegate 和 tableView.dataSource,因为我已经在 Storyboard 中分配了它们,但我想我会包括它们以确保你们都知道我知道有他们设置。
最佳答案
UITableViewDataSource
协议(protocol)发生了一点变化。尝试:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
关于ios - UITableView 和 UITableViewDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26723415/
我已经检查了其他几个问题,答案似乎在数据源方法的声明中。但是,我找不到我的方法声明有什么问题。 这是我的类(class): import UIKit class GuestControl: UITab
到目前为止,我很喜欢 MonoTouch,但是一旦您通过了几个初学者类(class),就会发现缺少文档和示例。 我正在努力解决在 MonoTouch 中填充简单 UITableView 的简单概念。我
在我们的应用程序中,我们有几个 UITableView,它们具有网络支持的数据源,实际填充这些数据源可能需要一些时间。以下是通常发生的情况: 用户触发 View 。 在 viewDidLoad 中,创
我有一个 UITableView,它应该呈现分成部分 的条目。数据需要一些时间来处理,因此它是这样完成的: @interface AsyncTable() NSMutableArray* _alp
数据源方法没有被触发我的 tableView 仍然是空的。使用断点,我可以看到数据源从未执行过我不明白为什么以及如何 import UIKit class SearchResultsViewContr
class EmployeeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var emp
我有一个 NSArray 从服务器获取的歌曲。那是我的原始数据源。该数组包含以 NSDictionary 和 NSArray 作为后端的自定义对象。 我想知道使用 NSDictionary 实现格式化
尝试将我的表的值分配给 self 时出现以下错误。 Cannot assign a value of type 'ActivityViewController' to a value of type
如何在 Swift 中定义协议(protocol):( @protocol Protocol - (Class)generateObject; @end 编辑:如果我想在 OC 中定义一个函数,如下
我在我的一个 UITableViews 中遇到索引越界异常,我认为可能是一些多线程问题。这是我认为正在发生的事情: 我有一个 UITableView,它的数据源是一个普通的 NSMutableArra
我在连接到 TodayViewController 的 ViewController 中使用 UITableView。我想使用我的 Parse 数据库中的数据加载到 TableView 中。 这是我的
我从 Xcode 模板创建了一个新的主从应用程序 我发现主界面(在本例中为 BirdMasterViewController)继承自 UITableViewController,和 UITableVi
我写代码有困难,协议(protocol)出错,我用的是xcode 7.3.1 //2 Method dari protokol UITableViewDataSource->method 1. fun
目前,我在我的应用程序中设置了以下内容: 例如,我有一个游戏列表,其中的游戏有不同的状态,我希望某个状态位于某个部分等。 因为我有 3 种不同的状态,所以我将使用 NSDictionary,其中 St
由于 UITableView 在 UIViewController 中,我创建了一个符合 UITableViewDataSource 协议(protocol)的类,并将其附加到 UIViewContr
我的项目中有 4 个文件: myTableViewController.swift myTableViewDataSource.swift myCustomCell.swift 我的自定义单元格.xi
我在 Xcode 8 beta 中编写了 tableView 的代码,然后尝试在实际的 Xcode 7 中执行它。除了 UITableViewDataSource 问题外,我下面的代码看起来是正确的。
问题:如何通过扩展编写 UITableViewDataSource 的默认实现? Swift支持协议(protocol)扩展中的默认实现,UITableViewDataSource是一个协议(prot
我设置了 tableview 数据源,但它无法识别他的错误类型“ViewController”不符合协议(protocol)“UITableViewDataSource” import UIKit c
因此,我在 Xcode 中收到“Type ViewController does not conform to protocol UITableViewDataSource”错误。我已经实现了所需的功
我是一名优秀的程序员,十分优秀!