我已在my.h文件@property (nonatomic, copy) NSDictionary *newsArticle;
上声明
在我。我有方法:
- (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方法上做同样的事情。
要访问这些值,我需要做什么?我需要访问值以传递到下一个视图 谢谢 罗德里戈
答案 0 :(得分:0)
您应该使用- (void)fetcheMovie:(NSData *)responseData
或想要推送下一个视图控制器的方法调用以下内容:
[self performSegueWithIdentifier:@"SegueIdentifier" sender:newsArticle];
在您的- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
中,发件人将成为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;
}
您必须相应地更改目标视图控制器的属性。您可以根据需要更改变量名称。