Im trying to create a GenericListController for my app.
I have a ProductListController that extend this generic controller which extends UIViewController. I have connected ProductListController to a storyboard and made 2 outlets, but i always receive this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7c158ca0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key searchBar.'
I receive this error for all my outlets, if i remove the generic T from GenericListController it works. I guess a storyboard cant load a super with generics. How can i make it work?
My code:
class GenericListController<T> : UIViewController {
var list : [T] = [T]()
var filteredlist : [T] = [T]()
func getData(tableView : UITableView) {
.....
}
func setData(list : [T], tableView : UITableView) {
.....
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
class ProductListController : GenericListController<ProductModel> {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
getData(tableView)
}
}
--EDIT--
I have found that if i extend an generic class and try to add the class to an storyboard xcode wont autocomplete the class name (probably because it cant detect the class)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…