【发布时间】:2011-07-26 05:06:54
【问题描述】:
我正在开发一个应用程序。我将图像视图放置在每个表格视图单元格中,例如
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
itemimageview=[[UIImageView alloc]initWithFrame:CGRectMake(5, 8, 75, 70)];
itemimageview.image=[UIImage imageNamed:@"thumb_mdpi.png"];
itemimageview.userInteractionEnabled = YES;
[cell.contentView addSubview:itemimageview];
return cell;
}
当您单击任何行时,我们会从 iPhone 相机中获取图像。为此,我在 didSelectROw 方法中编写了以下代码。
UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init]
autorelease];
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
//imagePicker.allowsImageEditing = NO;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
在我使用 UIIMagePickerController 委托方法之后
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"image selected");
itemimageview.image =image;
[self dismissModalViewControllerAnimated:YES];
}
但我的问题是选择图像后,该图像将仅出现在最后一个单元格。如果您选择第一行并拍摄图像,那么该图像将出现在最后一行。所以请告诉我有什么变化我获取每一行图像的代码。
【问题讨论】:
-
您可以通过在代码上添加断点来简单地检查。或者您使用 switch case 并编写代码,例如单击第一行然后显示此图像,然后选择第二行时显示此图像。我认为您有任何解决方案。
标签: iphone objective-c ios uitableview