[英]How can I create a new UIViewController by copying an existing one?
I want to create a new UIViewController that is very similar to an existing one. 我想创建一个与现有的UIViewController非常相似的新UIViewController。 I tried copying the files (old.m, old.h, and old.xib) and renaming them (new.m, etc.) The results, when added to the project, compile just fine, but I have a problem in the implementation of initWithNibName; 我尝试复制文件(old.m,old.h和old.xib)并重命名它们(new.m等)。将结果添加到项目中后,可以很好地进行编译,但是我遇到了问题initWithNibName的实现;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
someCustomWork(); // Not important for the problem, but the reason for this function!
}
return self;
}
The call to the super initWithNibName always returns (null), where for the original, a valid object is returned. 对超级initWithNibName的调用始终返回(空),对于原始的调用,将返回有效对象。
So, what am I missing here? 那么,我在这里想念什么? How can I best create a new UIViewController by copying the files of an existing one? 如何通过复制现有的UIViewController的文件来最好地创建一个新的UIViewController?
Thanks! 谢谢!
Heritage. 遗产。 Create a new blank VC and in the .h file: 在.h文件中创建一个新的空白VC:
#import "OldViewController.h"
@interface NewViewController : OldViewController
This will make the newVC have all the same functions and properties as the old one. 这将使newVC具有与旧VC相同的功能和属性。 Then override everything that must be different in the new one. 然后覆盖新的所有必须不同的内容。
Not sure about the xib files, never worked with storyboards. 不确定xib文件,也从未使用过故事板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.