Reputation: 61
I have navigation controller and every VC has customTableView. In my customTableView I put UI settings inside init()
method like this:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
separatorColor = UIColor.orange
}
but it doesn't work. But any other parameters of tableView like backgroundColor, sectionIndexColor and others work well. So I got problem only with separator color. Just to say, all my views and cells have clearColor.
If I put this code in view controller (that has an outlet of my customTableView) inside viewDidLoad
method - then it works. What I'm trying to achieve is to have only one subclassed UITableView class with predefined parameters to use in every VC in my navigation stacks.
Upvotes: 1
Views: 166
Reputation: 61
So, I found a way to make it work. I just override separatorColor
property in my customTableView class like this:
override var separatorColor: UIColor? {
get {
return UIColor.orange
}
set {
super.separatorColor = newValue
}
}
But I still cannot realise why this property cannot be set like others inside init()
method.
Upvotes: 1
Reputation: 424
There are at least two initializers that may be called:
1. required init?(coder aDecoder: NSCoder)
this initializer will be called when view will be initialized from Interface Builder (.xib or .storyboard). To initialize view from IB set the class of some view or subview to the view class you are using.
2. plain init()
will be called when you will initialize your view from code. There may be variation of this initializer, like init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
for UITableViewCell and so on.
So make sure if you are using right initializer. At least you can set breakpoint to see if this init is called or not.
Hope it helps!
Upvotes: 0