Search code examples
iosobjective-ccopynsmutabledictionary

Pass NSMutableDictionary from one view to another


I am trying to pass data from one ViewController to another ViewController.

Firstviewcontroller.m

-(void)NavigateToAnotherScreen:(NSMutableDictionary*)dict{
    [self performSegueWithIdentifier:@"NavDashBoardToInfo" sender:self];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"NavDashBoardToInfo"])
    {
        InfoViewController *vc = [segue destinationViewController];
        [vc setAppointmentDictionary:dict];
    }
}

Secondviewcontroller.h

@property (strong, nonatomic) NSMutableDictionary *AppointmentDictionary;

Secondviewcontroller.m

@synthesize AppointmentDictionary;

- (void)viewWillAppear:(BOOL)animated{
    NSLog(@"dict===>%@",AppointmentDictionary); // This gives me null
}

Please help me. What i am doing wrong.

I am getting AppointmentDictionary = (null) in viewwillappear. Though I am doing proper copy of this.


Solution

  • try this

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.destinationViewController respondsToSelector:@selector(setAppointmentDictionary:)]) {
        [segue.destinationViewController performSelector:@selector(setAppointmentDictionary:)
                                              withObject:dict];
    }
    }