NSDictionary为null,它在以前的View Controller中填充

时间:2013-11-12 05:00:26

标签: ios uitableview uiviewcontroller segue

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        NSLog((@"This is didSelectRowAtIndexPAth"));
        DetailViewController *detailViewController = [[DetailViewController alloc] init];
        detailViewController.myDictionary = [self.placeArray objectAtIndex:[indexPath row]]

//此MyDictionary NSdictionary在此处填充的其他viewController中声明..

        NSLog(@"My Dictionary: This is a MasterView one %@",detailViewController.myDictionary);

        UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        detailViewController = [mystoryboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

        //The below NSlog is showing the content , its not null still in next viewcontroller same variable showing null content

        NSLog(@"My Dictionary: This is a MasterView two %@",detailViewController.myDictionary);
        [self performSegueWithIdentifier:@"showDetail" sender:self];

}

2 个答案:

答案 0 :(得分:0)

为此目的使用PrepareForSegue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ DetailViewController * detailViewController = (DetailViewController*)segue.destinationViewController; detailViewController.myDictionary = [self.placeArray objectAtIndex:index]; }

答案 1 :(得分:0)

来自did select只使用prepareForSegue方法(希望你已经使用过。)通过xib或编程设置呈现视图控制器选项,然后停在那里.prepareForSegue会在使用storyboard时显示视图时自动调用。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DetailViewController *detailViewController = [[DetailViewController alloc] init];
        detailViewController.myDictionary = [self.placeArray objectAtIndex:[indexPath row]];  
}

编辑你did_select_method然后尝试。