0

ビューに 2 つのコンテナー ビューがあり、左側の分割ビュー コントローラー テーブルビューと右側の詳細ビューを模倣しようとしています。didselectmasters で行を使用すると、詳細ビ​​ューtableviewに詳細が表示されるはずです

問題は、データを詳細ビュー コントローラ インスタンスに渡すと、常に null が返されることです。

マスター上:

@property (nonatomic,strong) LogDetailViewController *wods;
UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                  bundle:nil];
    self.wods= [sb instantiateViewControllerWithIdentifier:@"LogDetailViewController"];
//also tried self.wods= [[LogDetailViewController alloc] init];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     //one of the if else method rest of it was too long
     else if ([indexPath section]==1){
        GIRLS *girls =[self.girlsList objectAtIndex:indexPath.row];
        self.wods.girls = girls;
        self.wods.section=1;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshLOGDetails" object:nil];
    }
}

ここに画像の説明を入力

ここに画像の説明を入力

ここに画像の説明を入力

詳細に:

@property  int section;
@property (nonatomic, strong) GIRLS *girls;
//refresh notification
extern NSString * const NOTIF_refreshLOGDetails;
@synthesize section;
@synthesize girls;

- (void)refreshLOGDetails:(NSNotification *)notif
{
    NSLog(@"Notification refreshLOGDetails works");
    [self configureView];
}
- (void)configureView
{  
 //also tried self.girls and self.section 
  NSLog(@"Section is %i",section);
  NSLog(@"configure view object %@",girls);

}

出力:

Notification refreshLOGDetails works
Section is 0
configure view object (null)

私が間違っているのは何ですか?null 値を取得するのはなぜですか?

4

1 に答える 1

0

問題は、LogDetailViewController をインスタンス化するとき、または alloc init を使用するときに、LogDetailViewController の新しいインスタンスを作成していることだと思います。これらをストーリーボードのコンテナー ビューでコントローラーとして設定する場合は、新しいものを作成するのではなく、そこで作成されたものを参照する必要があります。self.parentViewController を使用して、コンテナー ビューを含むコントローラーへの参照を取得できます。self.parentViewController.childViewControllers は、マスターと詳細を含む配列を提供します。その配列から正しいものを取得して返すだけです。

于 2013-02-08T21:26:09.757 に答える