继承UIViewController类和XIB

Van*_*nel 6 iphone objective-c uiviewcontroller ios

我正在开发一个iOS 4应用程序,我开发了一些我想在其他项目中使用的类.

其中一个类叫做MapViewControllerUIViewController子类.此类使用我使用界面构建器创建的XIB文件.

我想知道是否MapViewController在另一个项目中使用作为新类的超类,我如何使用它关联XIB?

我想重用MapViewController它和它的XIB,但我不知道我是否必须对XIB文件做一些特别的事情.

我不知道怎么解释这个.如果您需要更多详细信息,请告诉我.

更新:

我想创建一个继承自的新类MapViewController,如下所示:

...
@interface NewMapViewController : MapViewController {

...
Run Code Online (Sandbox Code Playgroud)

而且,现在如果我想继续使用相同的XIB(来自MapViewController),我该怎么办?

Mad*_*nRP 6

既然你要继承MapViewController,你MapViewController就会成为超级阶级.而且你还有MapViewController.xib.如果您使用初始化程序,对我来说似乎非常简单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;
}
Run Code Online (Sandbox Code Playgroud)

初始化NewMapViewContoller,如:

//Nib of super class is MapViewController
NewMapViewController *nmapController = [[NewMapViewController alloc] initWithNibName:@"MapViewController" bundle:[NSBundle mainBundle]];
Run Code Online (Sandbox Code Playgroud)