Can I use viewDidLoad method in UITableviewCell?
If you're trying to initialise some IBOutlets of your UITableViewCell, you may want to go for the awakeFromNib() call:
override func awakeFromNib() {
super.awakeFromNib()
// Do your stuff
// myIBOutlet.text = "Hello"
}
Better to call super.layoutSubviews()
as well. Swift syntax:
override func layoutSubviews() {
super.layoutSubviews()
}
No you don't write viewDidLoad in Custom cell class subclassing UITableViewCell(It;s part of UIViewController) .you have a method called
-(void)layoutSubviews
{
[super layoutSubviews];
}
where in you can define frames and all for custom cell's controls.Refer Apple's UITableviewCell reference
Note however that 'viewDidLoad' is called only once in the lifetime of the object; it is rather like an initializer in general OO programming. However, 'layoutSubviews' will be called many times on each cell (depending on issues like scrolling and so on). It's important to realize that for this reson many of the things you "usually do" in viewDidLoad, you can not do in layoutSubviews.
Note that viewDidLoad is called once only: layoutSubviews is called often.
It will just be a simple function if you write it.
Tutorial for custom cell