有没有办法选择在UITable iOS中使用的特定图像?

时间:2013-01-28 14:38:12

标签: ios6 uiimageview uiimage

我有一个UITable,我喜欢在单元格的详细信息视图中添加图像。我可以处理来自相机胶卷或相机的任何图像的选择:

cell.imageView.image = someImage;

但是如何定义特定图像 - 在上面的例子中:“someImage”,以便下次运行应用程序时,会显示每个项目的正确图像。

更新。这是我用来捕捉/选择图像的代码..

- (IBAction)btnTakePicture_Clicked:(id)sender
{
    NSLog(@"%s", __FUNCTION__);
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.alpha=0.90;
    actionSheet.tag = 1;
    [actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s", __FUNCTION__);
    switch (actionSheet.tag)
    {
        case 1:
            switch (buttonIndex)
        {
            case 0:
            {
#if TARGET_IPHONE_SIMULATOR

                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Ooops" message:@"Camera not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];

#elif TARGET_OS_IPHONE

                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                picker.delegate = self;
                //picker.allowsEditing = YES;
                [self presentViewController:picker animated:YES completion:nil];


#endif
            }
                break;
            case 1:
            {
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                picker.delegate = self;
                [self presentViewController:picker animated:YES completion:nil];
            }
                break;
        }
            break;

        default:
            break;
    }
}


-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    NSLog(@"%s", __FUNCTION__);
    dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
    imgPicture.image = [[UIImage alloc] initWithData:dataImage];

    [picker dismissViewControllerAnimated:YES completion:nil];
}

更新2.在以下人员的帮助下,我认为这个解决方案对我有用:

- (IBAction)photoLibraryAction:(id)sender
{   
    int c = self.capturedImages.count;
    for (int i=0; i < c; i++ ){
        if (self.imageView.tag == cellTag) {
            NSLog(@"found it");
    } else {
        NSLog(@"can't find it");
    }
    }
}


 if ([self.capturedImages count] == 1)
        {
            // we took a single shot
            [self.imageView setImage:[self.capturedImages objectAtIndex:0]];
          [self.imageView setTag:myTag];
        }

1 个答案:

答案 0 :(得分:1)

我会这样做。

@interface CustomClassCell : UITableViewCell
  @property (unsafe_unretained, nonatomic) IBOutlet UIImageView *HomePicture;
@end

@interface CustomClass : NSObject
   @property (nonatomic, copy) NSString *PicPath;
@end


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath      
{
   CustomClassCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomClassCellIdentifer"];
   id object = [self.tableData  objectAtIndex:indexPath.row];
   CustomClass *myObject = (CustomClass*)object;
   cell.HomePicture.image = [UIImage imageNamed:myObject.PicPath];
   return cell;
}