首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在当前视图控制器中调用NSDictionary

在当前视图控制器中调用NSDictionary
EN

Stack Overflow用户
提问于 2011-03-10 17:34:45
回答 3查看 442关注 0票数 1

我有一个函数,在这个函数中,我从其他视图控制器中定义的字典调用值。我必须在当前视图控制器的view didload方法中调用此方法。

下面是我的代码:

代码语言:javascript
运行
复制
-(void)setData:(NSDictionary *)dic {

self.jsonLabel.text = [dic objectForKey:@"Description"];
self.jsonImage.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [dic objectForKey:@"PictureURL"]]]];}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-03-11 13:27:26

尝尝这个

代码语言:javascript
运行
复制
NSURL *jsonURL = [NSURL URLWithString:[jsonItem objectForKey:@"PictureURL"]];

更新:

当第二个视图控制器在其alloc init方法中时,请注意分配字典。然后,您可以将字典从第一个视图控制器作为

代码语言:javascript
运行
复制
secondViewController.dict = self.dict;

然后按下第二个视图控制器。在viewDidLoad:中检查字典的值,如果字典可用,则可以继续。

代码语言:javascript
运行
复制
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//make sure jscontroller is allocated before this point.
NSDictionary *tempDict = [[NSDictionary alloc]init];
// set tempDict here with value or object aBook.PictureURL.
jscontroller.jsonItem = tempDict;
[tempDict release];
 NSLog(@"json ndic.......%@", jscontroller.jsonItem);
 [self.navigationController pushViewController:jscontroller animated:YES];
} 
票数 0
EN

Stack Overflow用户

发布于 2011-03-10 17:41:10

如果viewControllerObject是定义此函数的视图控制器的必要对象,则分配该对象并像这样调用

代码语言:javascript
运行
复制
- (void)viewDidLoad {

[viewControllerObject setData:urDict];

}
票数 0
EN

Stack Overflow用户

发布于 2011-03-10 18:06:07

我在其他的视图控制器中使用了这段代码

并尝试在currentViewController中检索

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

代码语言:javascript
运行
复制
 {
JSONViewController *controller = [[JSONViewController alloc] initWithNibName:@"JSONView" bundle:nil];
EmpDictionary=[[NSMutableDictionary alloc]init];
[EmpDictionary setValue:aBook.Description forKey:@"Description"];
[EmpDictionary setValue:aBook.PictureURL forKey:@"PictureURL"];
[EmpDictionary setValue:aBook.WeatherID forKey:@"WeatherID"];
EmpArray=[[NSMutableArray alloc]init];
[EmpArray addObject:EmpDictionary];
NSDictionary *itemAtIndex = [self.EmpArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:controller animated:YES];
[controller setData:itemAtIndex];}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5257751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档