Answer the question
In order to leave comments, you need to log in
How to implement same methods working with tableView in UITableViewController and UIViewController?
This question has already been raised ( How to avoid code duplication in two base classes inherited from UIViewController and UITableViewController? ), but it was a long time ago and I decided not to raise an old topic.
I have a lot of different view controllers in my project, I prefer to use them rather than UITableViewController
.
In the root subclass for my view controllers (let it be ) there is a regular . There is also a method for handling the appearance of the keyboard and all sorts of other methods where I sometimes use .
Everything is fine until you have to use static cells in the table. Then the question arises, how to inherit everything that I have accumulated inBaseViewController : UIViewController
@property UITableVIew *tableView
KeyboardWillShow/KeyboardWillHide
tableView
BaseViewController
? Reasonable remark: bring the whole thing into a category, for UIViewController
, but there is a name conflict tableView
for UITableViewController
.
In general, how do you solve this issue?
Answer the question
In order to leave comments, you need to log in
I do not use tableviewcontroller because there is no need. Static tables are solved by static code.
I agree that it is better not to use UITableViewController at all. But I can understand you too, I want to quickly throw a screen in the storyboard and not bother. Here are the solutions I used:
1) for new apps ( >= iOS 9) Use UIStackView. Ideal for this kind of task and does not require unnecessary gestures, which requires uitableview
2) Using a new approach, so promoted by Apple in swift instead of OOP - protocol oriented programming.
You declare your protocol for working with tableView, where you declare the readonly property NSArray *tableViews (who said that there can only be one table on the controller ;) ), or at worst myTableView
You declare your category/extension in swift terminology (or rather a set of them) on UIViewController, where the above protocol and the above property are used.
Further in UITableViewController you implement this protocol
- (NSArray <UITableView*> *) tableViews{
return @[self.tableView];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question