【问题标题】:Having trouble passing NSString from plist to ImageView将 NSString 从 plist 传递到 ImageView 时遇到问题
【发布时间】:2013-05-28 00:19:35
【问题描述】:

我目前正在使用 plist 来填充我的表格视图行(即名称、描述和图像)。当用户选择一行时,会向上推一个新的控制器,其中一个 imageView 会全屏显示该行的图像。

我面临的问题是将字符串传递给新的 viewController 的 imageView。

所有的 NSLog 都返回了正确的信息,除了当它记录 UIImageView 时,它返回 null。我没有正确连接它吗?该行在被选中之前不会显示任何图像(本质上该行正在起作用,类似于缩略图)。

任何帮助将不胜感激谢谢!!!

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

    NSDictionary *childDictionary = [mainChildren objectAtIndex:indexPath.row];

    //Image Name NSString from plist
    childImage = [childDictionary objectForKey:@"Child Image"];

    if ([childDictionary objectForKey:@"Child Image"] == nil) {

        NSLog(@"No Image String Found.");
    }

    else {

        NSLog(@"Image String Found. Image Name is: %@", childImage);

        UIImage *myImage = [UIImage imageNamed:childImage];
        NSLog(@"Image Found. Image is: %@", myImage);

        UIImageView *childImageView = [childImageView setImage:myImage];        
        NSLog(@"ImageView Found. ImageView is: %@", childImageView);

        FullscreenImageViewController *imgViewer = [[FullscreenImageViewController alloc] init];
        imgViewer.fullScreenImageView = childImageView;
        [self presentViewController:imgViewer animated:YES completion:nil];
    }
}

【问题讨论】:

    标签: ios objective-c uiimageview uiimage addsubview


    【解决方案1】:

    当你实例化一个新的 UIImageView 时,它应该是 [[UIImageView alloc] initWithImage:image]。

    或者由于您的全屏图像控制器具有图像视图的属性,例如fullScreenImageView,你可以直接用 UIImage 实例设置属性的图像。

    【讨论】:

    • 非常感谢。我无法弄清楚为什么图像没有被传递给 imageView,但这完全回答了我的问题。谢谢!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多