准备在ios上继续发布
我已在.h文件准备在ios上继续发布,ios,Ios,我已在.h文件@property(非原子,副本)NSDictionary*新闻文章中声明 在我的.m上,我有以下方法: - (IBAction)synopsis:(id)sender { NSString *urlString = [NSString stringWithFormat:@"http://api.themoviedb.org/3/movie/%@?api_key=34eb86f3b94de2676e8d3007b5ce1993",movieid]; dispatch
@property(非原子,副本)NSDictionary*新闻文章中声明代码>
在我的.m上,我有以下方法:
- (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方法中,我无法获得相同的值
我需要做什么才能访问这些值?我需要访问值才能传递到下一个视图
谢谢
Rodrigo您应该在-(void)fetcheMovie:(NSData*)responseData
中调用,或者在要推送下一个视图控制器的方法中调用以下命令:
[self performSegueWithIdentifier:@"SegueIdentifier" sender:newsArticle];
在您的-(void)prepareforsgue:(UIStoryboardSegue*)segue sender:(id)sender
中,发件人将作为performsgue
编辑
- (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;
}
您必须相应地从目标视图控制器更改属性。您可以随意更改变量名称。请格式化您的代码。谢谢DanyData,但您能告诉我如何构造(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender,我对sender部分感到困惑,它是“performsgue中的sendet as param”谢谢,但我遇到了一个错误,我猜是因为它缺少一个closiing“)”,我看到它在这里打开NSDictionary jsonSendetAsParamInPerformSegue=(NSDictionary,但我看不到它应该关闭在哪里,请在放置后告诉我)这就是我得到的结果:分配给cast是非法的。Ivalue强制转换不受支持我得到了要消除的错误,现在当我单击调用方法的按钮时,我得到了这样的消息:“NSInvalidArgumentException”,原因:“-[UIRoundedRectButton bytes]:未识别的选择器发送到实例0x95597a0”让我们