Overriding the parent of a class with a subclass - ios

I am looking for an efficient way to override the parent class of a UITableViewController. The parent class of UITableViewController is UIViewController. I have a subclass of UIViewController which is called SpecialViewController. I would like to make a subclass of UITableViewController called SpecialTableViewController. How can I achieve this?
UIViewController -> SpecialViewController -> UITableViewController -> SpecialTableViewController
Or am I breaking some rules?

I don't think its possible at compiletime. But its possible at runtime. Take a look here: Dynamically change an object's superclass

Related

UITableViewController inheriting from UIViewController

In order to fix bug I need to change a UIViewController into a UITableViewController. Only thing is that the current viewController is a subclass of a base UIViewController. How can I inherit behavior from base? Creating a whole other BaseTableViewController sounds very redundant.

How to link Table dataSource and delegate outlets to UITableViewController?

I'm new to Swift/iOS development.
I have a UITableView in my storyboard that I want to populate with some data. In my attempt to do so, I created a class that inherits from UITableViewController. The implementation is not yet complete, but my understanding is that by inheriting from this class I can provide an IBOutlet to both dataSource and delegate.
When I try to drag the outlet into the source file, I don't get the insertion point that I got when I tested this before. See image below:
What do I have to do to define this class as the handler for the UITableView?
Set your viewController to inherit from UIViewController, not from UITableViewController (It seems like your IB is set up like that).
Do not forget to set your class to ZeroconfTableController on the interface builder.
Than, you will be able to set the delegate and datasource. NOTE: the delegate and the datasource will not create IBOutlets.
Assign the delegate and the dataSource the following way:
Also make sure, your viewController conforms to the protocols.
class ZeroconfTableController: UIViewController, UITableViewDataSource, UITableViewDelegate {
In your storyboard, select the UITableView and change this to the name of your UITableViewController subclass. You then do not need to do any linking stuff.
If you're using your own UITableView, inherit from UIViewController, not UITableViewController.
If however, you want to use a UITableViewController (which personally I don't use) in your storyboard, then do inherit from UITableViewController. In this case you won't have to wire up the UITableViewDataSource nor the UITableViewDelegate.

How to create custom UIViewController then subclass already created UIViewControllers with it?

I have many classes subclasses of UIViewController. I would like to create another subclass of UIViewController and then make all my previous classes become subclasses of this one. Is that possible? If yes, how?
To clarify:
UIViewController > my previous UIViewControllers
now, what I would like:
UIViewController > new UIViewController > my previous UIViewControllers
Try looking up categories. They are an objective C way of extending a class. This way rather than having to go back and change your original code.

What superclass for a custom UI component?

I need to create a custom UI component that will satisfy the following:
it will contain a composition of UIViews, Labels, Button and a TableView.
it should be possible to instantiate it programatically - or - placing a UIView in nib editor and change the class in the inspector to my custom component class. (and it would the maintain/keep the main frame values from placed UIView)
I already started experimenting with it, I chose the UIView but it doesn't handle the ..cellForRow... cell method. On the other hand, if I use a UIViewController, then my class change in the inspector doesn't work and the app crashes.
Which one should I choose - UIView, UIviewController or NSObject?
I would go for UIViewController or UITableViewController, since you said you are having a tableView in it. If you do a UIViewController, you would probably have to include another UITableViewController inside it, using addChildViewController, as explained here
I believe the reason why your app is crashing is that you you changed your class superclass from UIView to UIViewController, but in the Interface Builder you still just have a UIView object. You need to change it to a UIViewController in the Interface Builder, and select your class as the File Owner.
If you intend this to be a stand-alone component, with all of the logic contained within the control, then I would base it on a UIViewController, like Apple does with the MFMailComposeViewController. If you want it to be strictly a view, with no built-in logic of its own, but instead delegates that logic, then use a UIView and delegate the table view methods to the controller that is using it.

Will a UIViewController subclass also affect my UITableViewControllers?

I need to add a common method to all my view controllers no matter what type they are. I notice though that some of my viewcontrollers inherit from UIViewController and some from UITableViewControllers.
How do I write a subclass that can be used for both?
UITableViewController inherits from UIViewController, so if you want to be able to call your custom method from both, you can write a category on UIViewController and then call methods from that category in any subclass of either UIViewController or UITableViewController. Here's a link to Apple's docs on categories and extensions. http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/chapters/occategories.html
if you add a category to UIViewController, you will be able to call those methods on UITableViewController subclasses, as UITableViewController is a subclass of UIViewController

Resources