Suppose you implement a custom table view and a custom view controller (which mostly mimics UITableViewControllers behaviour, but when initialized programmatically, …
@interface Foo : MyCustomTableViewController ...
Foo *foo = [[Foo alloc] init];
… foo.view is kind of class MyCustomTableView instead of UITableView:
// MyCustomTableView.h
@protocol MyTableViewDelegate <NSObject, UITableViewDelegate>
// ...
@end
@protocol MyTableViewDataSource <NSObject, UITableViewDataSource>
// ...
@end
@interface MyCustomTableView : UITableView
// ...
@end
// MyCustomTableViewController.h
@interface MyCustomTableViewController : UIViewController
// ...
@end
How should you implement/override init methods in correct order/ways so that you could create and use an instance of MyCustomTableView both by subclassing MyCustomTableViewController programmatically or from any custom nib file by setting custom class type to MyCustomTableView in Interface Builder?
It important to note that this is exactly how UITableView (mostly UIKit for that matter) works right now: a developer could create and use either programmatically or by creating from nib, whether be it File owner‘s main view or some subview in a more complex hierarchy, just assign data source or delegate and you’re good to go…
So far I managed to get this working if you subclass MyCustomTableViewController, where I will create an instance of MyCustomTableView and assign it to self.view in loadView method; but couldn’t figure out how initWithNibName:bundle:, initWithCoder:, awakeFromNib, awakeAfterUsingCoder:, or whatever else operates. I am lost in life cycle chain and end up with a black view/screen each time.
Thanks.
This is how I solved my own issue: