【发布时间】:2016-03-10 01:33:48
【问题描述】:
我有一个父视图 UIViewController(在故事板上),一个带有 .xib 的 TableViewController 和一个带有 .xib 的 TableViewCell。我正在尝试将 DataSource 连接到 TableView 但是它给了我一个错误:
“TableView1”与协议“UITableViewDataSource”的冗余一致性
'TableView1' 从这里的超类继承对协议 'UITableViewDataSource' 的一致性。
没有在类附近添加 dataSource 并尝试使用 class TableView1: UITableViewController {.. ,它不会给我任何错误,并且在模拟器中,当我向下滚动时,我可以看到表格视图错觉。
但是,当我尝试添加数据源时,它给了我这些错误。
我设置它的路径...:
-
Ctrl + 从 xib 拖动到 TableView1 并将其连接为
Globals -
在 xib 文件中,我连接了 DataSource & Delegate
- 最后,我的 TableView1:
class TableView1: UITableViewController, UITableViewDataSource { 此处出错..
@IBOutlet var GlobalsTableView: UITableView!
var results: [AnyObject]? = []
override func viewDidLoad() {
super.viewDidLoad()
print("A")
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return self.results?.count ?? 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! DogTableViewCell
return cell
}
}
请注意,在 TableView1.xib 中,我无法选择 TableView1 作为自定义类 -> 类(但我认为没有必要)。
【问题讨论】:
-
不指定
UITableViewDataSource会有什么问题?在你的课堂上class TableView1: UITableViewController { //... } -
我只是按照你说的删除了它。显然,我不需要它,我以为我需要它来传递数据
标签: xcode swift uitableview xib