iphone 2.x SDK-nullとして表示される別のviewController内のviewControllerへの参照

StackOverflow https://stackoverflow.com/questions/815422

質問

カスタムピッカービューコントローラーの新しく作成されたインスタンスに、別のviewControllerへの参照を与えようとしています(これは、tableView行がタップされた後に呼び出されるponceViewControllerインスタンスのセレクター内にあります)...


- (IBAction)rowTapped:(id)sender {
  TimerPickerViewController *viewController = [[TimerPickerViewController alloc] initWithNibName:@"TimerPickerView" bundle:nil]
  self.timerPickerViewController = viewController;
  timerPickerViewController.ponceViewController = self.rootViewController;
  [viewController release];
}

次に、私が持っているtimerPickerViewControllerインスタンス内に:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    ...
    // ponceViewController is null here
    ... 
  }
}

timerPickerViewControllerは正常に表示され、「完了」をタップするとponceViewControllerからもアクセスできます。ボタン、しかし、私はponceViewControllerを合成しており、それは私のヘッダーとすべてにあり、timerPickerViewControllerのinitWithNibNameメソッド内ではアクセスできないようです-それは常にnullです。 :(アイデアはありますか?

編集:timerPickerViewControllerのviewDidLoadメソッド内でもponceViewControllerがnullであることにも言及する必要があります...

- (void)viewDidLoad {
  ... no such thing as ponceViewController here! ...
}
役に立ちましたか?

解決

したがって、 initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil をtimerPickerViewControllerから完全に削除して修正し、代わりに viewDidLoad を使用しました。すべてがうまくいくようです。問題は、 initWithNibName 内でプロパティを参照するときに、プロパティがまだ使用可能でなかったためだと思います。それが他の誰かを助けることを願っています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top