So Ive built a custom cell class for my UITableView. Xcode insists that this UITableViewCell has the following initializer (Xcode actually auto-fills this code for me):
class customCell: UITableViewCell {
required init(coder aDecoder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Ive modified the contents of this initializer to contain the following:
// fatalError("init(coder:) has not been implemented")
super.init(coder: aDecoder)
If I remove the keyword required then Xcode kicks out an error and wants to correct me by putting the keyword back in.
So in my UITableView class I try to register this cell like so:
override func viewDidLoad(){
super.viewDidLoad()
let coder: NSCoder = NSCoder()
let customCell: AnyClass = customCell(coder: coder)
table?.registerClass(customCell, forCellReuseIdentifier:"cell")
The penultimate line (the one where I initialize the customCell with the NSCoder, as Xcode wants me to) produces the error:
Cannot invoke 'init' with an argument list of type '(coder: NSCoder)'
If I can I'd prefer to build my own initializer without an NSCoder.
If I try to use any other initializer then Xcode kicks out an error along the lines of:
Extra argument 'reuseIndenifier' in call
or
Missing argument in call
It will continue complaining until I am using the initializer with NSCoder. I am forced into using this initializer.
Please correct me if I am way off here, but to me it seems like I am caught in an catch 22 situation - Xcode complains if I build an initializer without a coder, and then when I try to use an initializer with a coder it complains that I am using a coder.
Despite this apparent contradiction I am fairly convinced all of this is a result of me being a dumbass somewhere.
Would anyone out there be kind enough to point me in the right direction?
UITableViewCellprogrammatically - please see this question: stackoverflow.com/questions/27103278/…init(style style: UITableViewCellStyle, reuseIdentifier reuseIdentifier: String?), like I said, initWithCoder is called by interface builderrequired init(coder aDecoder:NSCoder)method and auto-completes it. Is this another Xcode bug? It has been suggested to me that I re-install Xcode.