即時通訊有麻煩重寫初始化方法爲我的故事板中設計的我的CustomViewController。視圖控制器自定義初始化方法與故事板
現在即時通訊做(在我mainViewController):
self.customViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomVC"];
self.customViewController.myObject = someObject;
和我在viewDidLoad中(CustomViewController)
[self.label setText:self.myObject.someString];
該工程確定。
但是,這是正確的方法嗎?我應該添加一個自定義的init方法(或覆蓋)到我的CustomViewController?像initWithObject一樣:?我不知道如何調用我的自定義初始化方法,而不是UIStoryboard instantiateViewControllerWithIdentifier:
,並且我沒有接到調用init
或initWithNibName
。我可以使用:- (id)initWithCoder:(NSCoder *)decoder
。
請給我一些建議!
謝謝!
你正在做的一切都正確。你可以在你的自定義類中覆蓋initWithCoder,也就是你的_customViewController對象的類文件來做自定義init – 2013-07-05 04:19:40