Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherit UIViewController class and XIB

I'm developing an iOS 4 application and I have developed some classes that I want to use in others projects.

One of this classes, called MapViewController, is a UIViewController subclass. This class uses a XIB file that I've created with interface builder.

I'm wondering if a use MapViewController in another project as a super class from a new class, How can I use it associated XIB?

I want to reuse MapViewController and its XIB, but I don't know if I have to do something special with the XIB file.

I don't know how to explain this. If you need more details, please tell me.

UPDATE:

I want to create a new class that inherit from MapViewController, like this:

...
@interface NewMapViewController : MapViewController {

...

And, now if I want to continue using the same XIB (the one from MapViewController), what must I do?

like image 222
VansFannel Avatar asked Dec 28 '11 15:12

VansFannel


1 Answers

Since you are gonna inherit from MapViewController, your MapViewController becomes the super class. And you also have MapViewController.xib. It seems pretty straightforward to me if you use the initializer for NewMapViewController

NewMapViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    NSLog(@"Subclass initWithNibName called");
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

Initialize your NewMapViewContoller like:

//Nib of super class is MapViewController
NewMapViewController *nmapController = [[NewMapViewController alloc] initWithNibName:@"MapViewController" bundle:[NSBundle mainBundle]];
like image 80
MadhavanRP Avatar answered Oct 23 '22 03:10

MadhavanRP