2013-10-19 67 views
0

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

- (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方法添加

回答

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 instace的财产ImageViewController.h

@property (nonatomic , retain) UIImage *selectedImage;

0

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

  1. 在subViewController中定义一个属性,并在导航到subViewController之前,在parentViewController中分配值。
  2. 在导航到subViewController之前传递图像路径。在subViewController中显示基于imagePath的图像。
相关问题