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:
Redundant conformance of 'TableView1' to protocol 'UITableViewDataSource'
'TableView1' inherits conformance to protocol 'UITableViewDataSource' from superclass here.
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.
The path I followed on setting it up...:
Ctrl + drag from xib to TableView1 and connected it as Globals
In xib file, I connected DataSource & Delegate
class TableView1: UITableViewController, UITableViewDataSource {
error here..
@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
}
}
Please note that in TableView1.xib, I can't select TableView1
as Custom Class -> Class (but i don't think it's necessary).
When a class inherits from UITableViewController
, it by default conforms to UITableViewDataSource
& UITableViewDelegate
and you need not explicitly specify it.
You need to conform to UITableViewDataSource
and UITableViewDelegate
only when you embed a UITableView
in a UIViewController
.
There are at least 2 conformations in your class. You need to extend only once.
First Scenario:
You conform in the class description AND in the extension.
class MyViewController: MyDelegate{
//class functions here
}
extension MyViewController: MyDelegate{
func1()
}
Remove "My Delegate" in the class description.
class MyViewController{
//class functions here
}
extension MyViewController: MyDelegate{
func1()
}
Second Scenario:
You conform in two extensions.
extension MyViewController: MyDelegate{
func1()
}
extension MyViewController: MyDelegate{
func2()
}
Merge them into one extension like:
extension MyViewController: MyDelegate{
func1()
func2()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With