【Objective-C】Embed Inで追加したNavigation Controllerの配下にあるViewControllerに値を渡したい
Navigation Controllerの先にあるViewControllerに値を渡したいと思う。
普通に渡したい先のViewControllerのインスタンスを生成して処理を書く。
「unrecognized selector sent to instance」のエラーが表示。
内容を見るとNavigationControllerにset〜:のセッターがないよ!って内容。
渡したいのはその先のViewControllerなのに。
環境
- Xcode6.1.1
- CのViewControllerには.hにプロパティを用意済み
- Segueを使用
解決方法
// propertyを用意 @property (nonatomic) NSString *pageURL;
#import "C_ViewController.h" - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // StoryBoard SegueのIdentifierの値が同じなら(複数Segueが存在する場合に) if ([[segue identifier] isEqualToString:@"対象のSegueのIdentifier"]) { // Embed Inで追加したNavigationControllerの先にあるViewControllerに値を渡す UINavigationController *navigationView = [segue destinationViewController]; C_ViewController *c_View = (C_ViewController*)navigationView.visibleViewController; c_View.pageURL = @"渡したい値"; } }