This question already has answers here:
Passing Data between View Controllers
                                
                                    (43个答案)
                                
                        
                                3年前关闭。
            
                    
我试图将数据从一个ViewController传递到另一个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
}


请帮我。我做错了。

我在AppointmentDictionary = (null)中得到viewwillappear
尽管我正在对此做适当的复制。

最佳答案

尝试这个

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

09-11 18:56
查看更多