我在尝试覆盖Storyboard中设计的CustomViewController的初始化方法,但遇到了问题。
现在我正在我的mainViewController中这样做:
self.customViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomVC"];
self.customViewController.myObject = someObject;
我在CustomViewController的viewDidLoad方法中有如下代码:
[self.label setText:self.myObject.someString];
这个方法可以正常工作。
但是,这是否是正确的方法呢?我应该向我的CustomViewController添加一个自定义的init方法(或重写)吗?比如initWithObject:?我不知道如何调用我的自定义初始化方法,而不是使用“UIStoryboard instantiateViewControllerWithIdentifier:”,并且我没有收到对“init”或“initWithNibName”的调用。
也许我应该使用: -(id)initWithCoder:(NSCoder *)decoder
。
请给我一些建议!
谢谢!