I have read the following articles:
- creating custom tableview cells in swift
- 'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'`
- Custom UITableViewCell from nib in Swift
However, none of them have solved my problem.
What I am trying to accomplish:
I want to dynamically create buttons in a tableview cell like as described in this post. So that I can create as many buttons I want to in a tableview cell.
The problem:
However, I keep getting the error fatal error: init(coder:) has not been implemented
.
What I have done so far:
In my tableview cell class I have the following code:
var cellButton: UIButton!
init(title: String) {
super.init(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
cellButton = UIButton(frame: CGRectMake(5, 5, 50, 30))
cellButton.setTitle(title, forState: UIControlState.Normal)
addSubview(cellButton)
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
}
In my tableview class I have written the following code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = OfficeConnectUserTableViewCell(title: "hello")
return cell
}
Any suggestions to get rid of the error and dynamically create the button inside the cell programmatically?