Inherit class UIViewController and XIB

I am developing an iOS 4 application and I have developed some classes that I want to use in other projects.

One of these classes, called MapViewController , is a subclass of UIViewController. This class uses the XIB file that I created using the interface constructor.

I am wondering if using MapViewController in another project as a superclass from a new class, How can I use the associated XIB?

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

I do not know how to explain it. If you need more information, let me know.

UPDATE:

I want to create a new class that inherits from MapViewController , for example:

 ... @interface NewMapViewController : MapViewController { ... 

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

+6
source share
1 answer

Since you inherit from MapViewController , your MapViewController becomes a superclass. And you also have MapViewController.xib. It seems pretty simple 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 as:

 //Nib of super class is MapViewController NewMapViewController *nmapController = [[NewMapViewController alloc] initWithNibName:@"MapViewController" bundle:[NSBundle mainBundle]]; 
+6
source

Source: https://habr.com/ru/post/904606/


All Articles