【发布时间】:2012-04-03 03:09:38
【问题描述】:
我无法覆盖我在 Storyboard 中设计的 CustomViewController 的初始化方法。
现在我在做(在我的 mainViewController 中):
self.customViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomVC"];
self.customViewController.myObject = someObject;
我有 viewDidLoad (CustomViewController)
[self.label setText:self.myObject.someString];
这没问题。
但是,这是正确的方法吗?我应该向我的 CustomViewController 添加自定义初始化方法(或覆盖)吗?像 initWithObject: ?我不知道如何调用我的自定义 init 方法而不是 UIStoryboard instantiateViewControllerWithIdentifier:,而且我没有接到对 init 或 initWithNibName 的调用。
也许我应该使用:- (id)initWithCoder:(NSCoder *)decoder。
请给我一些建议!
谢谢!
【问题讨论】:
-
你做的一切都是对的。您可以在您的自定义类中覆盖 initWithCoder,即您的 _customViewController 对象的类文件以进行自定义初始化
标签: ios5 uiviewcontroller uistoryboard