I am trying to have a super class fill and handle the contents of a table for a certain segment. So I thought of implementing:
@IBAction func changeValue(sender:AnyObject){
self.searchDisplayController?.setActive(false, animated:false)
if (selection.selectedSegmentIndex==1){
self.myTableView.delegate=super
self.myTableView.dataSource=super
} else {
self.myTableView.delegate=self
self.myTableView.dataSource=self
}
self.myTableView.reloadData()
}
Yet I had an error. By way of testing, the compiler suggested me to use:
@IBAction func changeValue(sender:AnyObject){
self.searchDisplayController?.setActive(false, animated:false)
if (selection.selectedSegmentIndex==1){
self.myTableView.delegate=super.self()
self.myTableView.dataSource=super.self()
print("type: \(super.self())")
} else {
self.myTableView.delegate=self
self.myTableView.dataSource=self
}
self.myTableView.reloadData()
}
whatever the meaning of construct super.self()
Yet, notwithstanding the code passes through there without any problem, the command seems to be ignored and the delegate methods are called on the same class instead of the super one and even printing the value of super.self() shows it is the current class, notwitstanding, when I skip the (), Xcode encourges me by saying:
Function produces expected type 'LogsViewController'; did you mean to call it with '()'?
Yet when I add the double parenthesis it return the current class instead of the top LogsViewController.
What is the correct way of implementing what I need, and why super.self() does not work as it is advertised?
I am reporting the cehma of my pattern implmentation, should it be unclear:
Bottom class:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
/
/
let isMainTable = tableView==self.myTableView
let isFavorite = selection.selectedSegmentIndex==2
var count: Int?
count = sourceForTableKind(isMainTable, favorites:isFavorite)?.count
if (count==nil) {
return 0
}
return count!
}
Top "virtual" class:
func sourceArray()->Array<NearElement>?{
return nil
}
func arrayOfContentsFromSearchArray(searchArray:Array<String>?, favorites:Bool)->Array<NearElement>?{
return nil
}
func sourceForTableKind(normal: Bool, favorites:Bool)->Array<NearElement>?{
/
print("sono \(self)")
if (normal) {
return sourceArray()
} else {
return arrayOfContentsFromSearchArray(searchResults, favorites:favorites)
}
}