私のストーリーボードで設計した私のCustomViewControllerの初期化メソッドをオーバーライドするのに問題があります。viewControllerストーリーボードでカスタムinitメソッド
は今(私のmainViewControllerで)やってイム:
self.customViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomVC"];
self.customViewController.myObject = someObject;
と私は、これはうまく動作のviewDidLoad(CustomViewController)
[self.label setText:self.myObject.someString];
を持っています。
しかし、それは正しい方法ですか? CustomViewControllerにカスタムのinitメソッド(またはオーバーライド)を追加する必要がありますか? initWithObjectのように:?私はUIStoryboard instantiateViewControllerWithIdentifier:
の代わりに私のカスタムinitメソッドを呼び出す方法を知らないし、init
もinitWithNibName
も呼び出していない。
多分私は使用する必要があります:- (id)initWithCoder:(NSCoder *)decoder
。
お願いします。
ありがとうございました!
あなたがやっていますすべての権利。カスタムクラスのinitWithCoderをオーバーライドすることができます。つまり、カスタムのinitを実行するための_customViewControllerオブジェクトのクラスファイルです。 –