我有一个函数,在这个函数中,我从其他视图控制器中定义的字典调用值。我必须在当前视图控制器的view didload方法中调用此方法。
下面是我的代码:
-(void)setData:(NSDictionary *)dic {
self.jsonLabel.text = [dic objectForKey:@"Description"];
self.jsonImage.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [dic objectForKey:@"PictureURL"]]]];}发布于 2011-03-11 13:27:26
尝尝这个
NSURL *jsonURL = [NSURL URLWithString:[jsonItem objectForKey:@"PictureURL"]];更新:
当第二个视图控制器在其alloc init方法中时,请注意分配字典。然后,您可以将字典从第一个视图控制器作为
secondViewController.dict = self.dict;然后按下第二个视图控制器。在viewDidLoad:中检查字典的值,如果字典可用,则可以继续。
- (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];
} 发布于 2011-03-10 17:41:10
如果viewControllerObject是定义此函数的视图控制器的必要对象,则分配该对象并像这样调用
- (void)viewDidLoad {
[viewControllerObject setData:urDict];
}发布于 2011-03-10 18:06:07
我在其他的视图控制器中使用了这段代码
并尝试在currentViewController中检索
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
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];}https://stackoverflow.com/questions/5257751
复制相似问题