0

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];
        }
4

1 に答える 1

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;
}
于 2013-01-28T15:19:53.630 に答える