2011-12-28 75 views
6

我正在开发iOS 4应用程序,并且我开发了一些我想在其他项目中使用的类。继承UIViewController类和XIB

其中一个类叫做MapViewController,它是一个UIViewController子类。这个类使用我用界面构建器创建的XIB文件。

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

我想重用MapViewController及其XIB,但我不知道是否必须对XIB文件做一些特殊的处理。

我不知道该如何解释。如果你需要更多的细节,请告诉我。

UPDATE:

我想创建一个新的类,从MapViewController继承,像这样:

... 
@interface NewMapViewController : MapViewController { 

... 

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

+0

让我试着去了解,你想:如果您使用的初始化为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; } 

初始化您NewMapViewContoller像它看起来相当简单的我能够使用你的MapViewController和他的XIB,但是如果你需要一些特殊的行为,你不想使用XIB? – Peres 2011-12-28 15:19:30

+0

目前尚不清楚确切的问题是什么。 – Max 2011-12-28 15:52:06

+1

对不起。我刚刚更新了我的问题,并提供了更多细节。 – VansFannel 2011-12-28 16:00:49

回答

6

既然你要继承MapViewController,你的MapViewController成为超级类。你也有MapViewController.xib。

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

不,它不。我试过了。事实上,initWithNibName永远不会被调用。 – 2013-01-22 00:45:11

+0

@JimThio我编辑了我的答案。我测试了这个,它适用于我。尝试一下,让我知道。 – MadhavanRP 2013-01-22 06:26:54

+0

在iOS 9.2中为我工作,谢谢! – webo80 2016-01-13 09:43:45