当前位置:  开发笔记 > 编程语言 > 正文

TableView与协议UITableViewDataSource与Xib文件的冗余一致性

如何解决《TableView与协议UITableViewDataSource与Xib文件的冗余一致性》经验,为你挑选了1个好方法。

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

"TableView1"与协议"UITableViewDataSource"的冗余一致性

'TableView1'继承了来自超类的协议'UITableViewDataSource'的一致性.

如果不在类附近添加dataSource并尝试它class TableView1: UITableViewController {..,它不会给我任何错误,在模拟器中,当我向下滚动时,我可以看到表视图错觉.

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

我设置它的路径......:

    按住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自定义类 - >类(但我不认为这是必要的).



1> R P..:

当一个类继承时UITableViewController,它默认符合UITableViewDataSource&UITableViewDelegate,你不需要显式指定它.

你需要遵守UITableViewDataSource并且UITableViewDelegate只有当你嵌入UITableView一个UIViewController.

推荐阅读
无名有名我无名_593
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有