I’m new at iOS development. I have two table views and a content detail view something like this:
PopularContentViewController : UITableViewController
LatestContentViewController : UITableViewController
ContentDetailViewController : UIViewController
I want to add some authentication so that before any of these controllers is loaded, I can ensure that the user is logged in, and if not, show a modal login view controller.
My thinking was to create my own UIViewController subclass (say, AuthenticatedViewController) and make my other controllers inherit it. The problem is, how do I do something like this:
PopularContentViewController : UITableViewController : AuthenticatedViewController
LatestContentViewController : UITableViewController : AuthenticatedViewController
ContentDetailViewController : AuthenticatedViewController
I found this similar question: Can I create a UITableViewController that inherits from a custom subclass of UIViewController?
… but I’m wondering if there’s another way to do this other than inheritance or creating my own UITableViewController that extends my AuthenticatedTableViewController? Maybe through protocols or by using a delegate instead? Just looking for a nudge in the right direction.
Uitableviewcontrollers is a UIViewController. But you’re going about this the wrong way. Create a root view controller for authentication, perhaps place that in a navigation controller. Then one the user is authenticated, push one of your tableview controllers onto the stack (or replace the original controller entirely at runtime and save off it’s credentials). …
Or, if you insist, use categories or a singleton just to deal with authentication back end stuff (leave the UI out of that when possible). I’d go the way of one view controller per job (in a navigation controller container) … Simplify, man, simplify.