Can I use viewDidLoad
method in UITableviewCell
?
viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.
viewDidLoad method is called only once in ViewController lifecycle. The reason retrieveMessage() is called in viewDidLoad because it's adding observer to start listening for received and sent message.
-viewDidLoad will be called once whenever the view controller needs to load its view hierarchy. Obviously, that'll happen the first time that the controller accesses its view. If the view controller later unloads its view, then -viewDidLoad will be called again the next time the view is loaded.
viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.
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.
It will just be a simple function if you write it.
Tutorial for custom cell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With