1

I'm missing something fundamental here.

I have a table view with each cell displaying the contents of an NSDictionary. When I tap on each cell I would like to segue to a new view controller displaying details from the same dictionary.

But every time i try pass the dictionary it's contents are null on the other side.

Here's my prepare for segue in the view controller containing the table view:

 -(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"tableSegue"]){

        MODetailViewController *detailViewController = [[MODetailViewController alloc] init];

        NSIndexPath *selectedIndexPath = [self.monetiseTable indexPathForSelectedRow];
        int selectedIndexPathAsInteger = selectedIndexPath.row;

        NSDictionary *dictionaryToPass = [[NSDictionary alloc] initWithDictionary:[self.feedArray objectAtIndex:selectedIndexPathAsInteger]];

        NSLog(@"%@", dictionaryToPass);

        detailViewController.passedDictionary = dictionaryToPass;
    }
}

The NSLog displays the dictionary as expected.

Now, in detail view controller header I have declared the property (i'm using ARC):

@property (weak, nonatomic) NSDictionary *passedDictionary;

Now in viewWillAppear:

-(void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:YES];

NSLog(@"%@", self.passedDictionary);
}

The NSLog is returning null!?

I have synthesised it.

I'm missing something fundamental i'm sure. Any help?

4

2 回答 2

3
@property (weak, nonatomic) NSDictionary *passedDictionary;

而不是weak,声明它strong

这将防止字典被释放。

祝你好运!

于 2012-04-06T14:15:45.957 回答
2

不要分配新的 MODetailViewController。使用传递给您的那个作为 segue 参数中的目标控制器。

于 2012-04-06T14:16:56.983 回答