0

我已经在 my.h 文件上声明了在@property (nonatomic, copy) NSDictionary *newsArticle; my.mi 上有以下方法:

- (IBAction)synopsis:(id)sender {
    NSString *urlString = [NSString stringWithFormat:@"http://api.themoviedb.org/3/movie/%@?api_key=34eb86f3b94de2676e8d3007b5ce1993",movieid];
    dispatch_async(kBgQueue, ^{
        NSURL *url = [NSURL URLWithString:urlString];
        NSData* data = [NSData dataWithContentsOfURL:url];
        [self performSelectorOnMainThread:@selector(fetcheMovie:)withObject:data waitUntilDone:NO];
    });
}

- (void)fetcheMovie:(NSData *)responseData {
    NSError* error;

    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData  options:kNilOptions error:&error];
    newsArticle= [NSJSONSerialization JSONObjectWithData:responseData  options:kNilOptions error:&error];
    NSLog(@"data1 = %@",newsArticle);
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    NSLog(@"data2 = %@",newsArticle);
    if ([[segue identifier] isEqualToString:@"web"]){
        WebViewController *vc = [segue destinationViewController];
        vc.imdbnumber=@"tt0105236rodrigo";
    }
}

在 fetcheMovie 方法上,我可以获得 newsArticle 的值,但在 prepareForSegue 方法上却不能。

我需要做什么才能访问这些值?我需要访问值才能传递到下一个视图谢谢罗德里戈

4

1 回答 1

0

您应该调用您的- (void)fetcheMovie:(NSData *)responseData或您想要推送下一个视图控制器的方法,如下所示:

[self performSegueWithIdentifier:@"SegueIdentifier" sender:newsArticle];

在您- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender的发件人中,将 newsArticle sendet 作为参数performSegue

编辑

- (void)fetcheMovie:(NSData *)responseData {
    NSError* error;
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData  options:kNilOptions error:&error];
    [self performSegueWithIdentifier:@"SegueIdentifier" sender:json];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      NSDictionary *jsonSendetAsParamInPerformSegue = (NSDictionary*)sender;

      newsArticle= [NSJSONSerialization JSONObjectWithData:jsonSendetAsParamInPerformSegue  options:kNilOptions error:&error];
      WebViewController *vc = [segue destinationViewController];
      vc.viewControllerProperty = newsArticle;
}

您必须相应地从目标视图控制器更改属性。您可以根据需要更改变量名称。

于 2013-05-07T15:59:57.477 回答