TableView 与协议 UITableViewDataSource 与 Xib 文件的冗余一致性 [英] Redundant conformance of TableView to protocol UITableViewDataSource with Xib Files
问题描述
我有一个父视图 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.
我设置的路径...:
Ctrl + 从xib 拖动到TableView1 并将其连接为
Globals
在xib文件中,我连接了DataSource &委托
In xib file, I connected 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
作为自定义类 ->类(但我认为没有必要).
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
时,才需要符合UITableViewDataSource
和UITableViewDelegate
.
You need to conform to UITableViewDataSource
and UITableViewDelegate
only when you embed a UITableView
in a UIViewController
.
这篇关于TableView 与协议 UITableViewDataSource 与 Xib 文件的冗余一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!