TableView 与协议 UITableViewDataSource 与 Xib 文件的冗余一致性 [英] Redundant conformance of TableView to protocol UITableViewDataSource with Xib Files

查看:27
本文介绍了TableView 与协议 UITableViewDataSource 与 Xib 文件的冗余一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父视图 UIViewController(在故事板上),一个带有 .xib 的 TableViewController 和带有 .xib 的 TableViewCell.我正在尝试将 DataSource 连接到 TableView 但是它给了我一个错误:

I have a parent view UIViewController (on storyboard), a TableViewController with .xib and TableViewCell with .xib. I am trying to connect DataSource to the TableView however it's giving me an error:

'TableView1' 对协议 'UITableViewDataSource' 的冗余一致性

Redundant conformance of 'TableView1' to protocol 'UITableViewDataSource'

'TableView1' 从这里的超类继承了对协议 'UITableViewDataSource' 的一致性.

'TableView1' inherits conformance to protocol 'UITableViewDataSource' from superclass here.

没有在类附近添加 dataSource 并尝试将其作为 class TableView1: UITableViewController {.. ,它不会给我任何错误,并且在模拟器中,我可以在滚动时看到表格视图错觉下来.

Without adding dataSource near class and try it as class TableView1: UITableViewController {.. , it doesn't give me any error and in the simulator, I can see the table view illusion when I scroll down.

但是,当我尝试添加数据源时,它给了我这些错误.

However, when I try to add dataSource, it gave me these errors.

我设置的路径...:

  1. Ctrl + 从xib 拖动到TableView1 并将其连接为Globals

在xib文件中,我连接了DataSource &委托

In xib file, I connected DataSource & Delegate

  1. 最后,我的 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 作为自定义类 ->类(但我认为没有必要).

Please note that in TableView1.xib, I can't select TableView1 as Custom Class -> Class (but i don't think it's necessary).

推荐答案

当一个类继承自 UITableViewController 时,它默认符合 UITableViewDataSource &UITableViewDelegate 并且您不需要明确指定它.

When a class inherits from UITableViewController, it by default conforms to UITableViewDataSource & UITableViewDelegate and you need not explicitly specify it.

只有在UIViewController中嵌入UITableView时,才需要符合UITableViewDataSourceUITableViewDelegate.

You need to conform to UITableViewDataSource and UITableViewDelegate only when you embed a UITableView in a UIViewController.

这篇关于TableView 与协议 UITableViewDataSource 与 Xib 文件的冗余一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆