views:

76

answers:

1

When you have an UIViewController and UITableViewController classes and you wanted to let these two do some common stuff in their - (void)viewDidLoad how could you achieve this in Objective-C without actually duplicating your code?

I tried to create MyUIViewController inheriting UIViewController and implement viewDidLoad in there. This perfectly works with UIViewController classes obviously, but won't work in UITableViewController, since I can't simply replace @interface MyTableViewController : UITableViewController with @interface MyTableViewController : MyUIViewController.

I believe this topic is about "multiple inheritance" in Objective-C language, but other than figuring out what's different in Objective-C, I'd really like to know how to do guys do such thing?

+1  A: 

This thread has some good information. One of your main options is to make a class with that shared functionality and hold it as an instance variable, then forward messages to it in forwardInvocation.

jtbandes
Yeah, forwardInvocation was what I also found out after all those readings that I've done. I hoped maybe there was another way of doing it. Thanks.
exalted