0

我可以用相机拍照并保存在文件夹中。图像将加载到UITableView. 如果我选择特定行,对应图像将转到下一个视图并显示图像。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSLog(@"Enter into cellforRow");

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSString *FileName = [NSString stringWithFormat:@"test1.png"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:FileName];

    //image
    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10.0, 10.0, 60.0, 60.0)];

    [imageView setImage:[arrayOfImages objectAtIndex:indexPath.row]];
    [cell.contentView addSubview:imageView];

    return cell;
}

现在在didSelectRowAtIndexPath方法中添加什么

4

2 回答 2

0

在您的didSelectRowAtIndexPath

UIImage *image = [arrayOfImages objectAtIndex:indexPath.row]; 
    ImageViewController *viewer = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil];
    viewer.selectedImage = image;
    [self.navigationController pushViewController:viewer animated:YES];

在中创建 UIImage 实例的属性ImageViewController.h

喜欢@property (nonatomic , retain) UIImage *selectedImage;

于 2013-10-19T14:11:59.267 回答
0

有两种方法可以在子视图控制器中显示图像。

  1. 在 subViewController 中定义一个属性,然后在导航到 subViewController 之前在 parentViewController 中分配值。
  2. 在导航到 subViewController 之前传递图像路径。在 subViewController 中显示基于 imagePath 的图像。
于 2013-10-20T05:44:43.163 回答