SubClassing in iPhone objective c to share the common class files

Go To


I am very new to iPhone. I have developed two version of an application in iphone. Here i have used individual class implementations depends upon version features.

For example ' ListViewController' class have .h,.m, xib files. with the same name in two versions, but different in some part (little bit difference) code implementation.

In 1st 'ListViewController' version shows only a table view. In 2nd version 'ListViewController' shows tableview and a button just bello the table view, to set the reminders (alarm).

So just the difference in InterfaceBuilder *button* (AlarmButton) & in Code button action -(IBAction)SetReminder.

Now I need to put all the same classes in a library (Common folder) for the two projects v1&v2,

Now i need to implemente 'ListViewController' as common for both versions using subClassing.

How do I achieve that, any help or examples or link.

2012-04-04 05:49
by Ranga


To share the same code between classes generally we use inheritance but there is a very cool feature added in objective-c that is category, find the tutorial link below:

Might Help...!!

2012-04-04 05:58
by Nilesh
You can also refer link for subclassing: - Nilesh 2012-04-04 05:59


To create a subclass you just need to create header and implementation files they should look like this

// header file
@interface MySubclassName : ListViewController


// implementation file
#import "MySubclassName.h"
@implementation MySubclassName

// methods you want to subclass

2012-04-04 05:57
by Otium