iam developing one application.In that i place the imageview in every tableview cell like
-(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;
}
And when u click any row we get the image from our iPhone camera.For that i write the below code in didSelectROw method.
UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init]
autorelease];
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
//imagePicker.allowsImageEditing = NO;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
After i use the UIIMagePickerController delegate method like
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"image selected");
itemimageview.image =image;
[self dismissModalViewControllerAnimated:YES];
}
But my problem is after selecting the image,that image will be appear at last cell only.If u select first row and take the image then that image will be appear at last row.So please tell me what are the changes in my code for getting the image for every row.
You can achieve this by following these steps:
1.First when the user clicks a cell, store the row number (indexPath.row) in an integer variable.
2.Once you have acquired the image from the camera,store it in a UIImage.
3.Now you know the row to be updated and you have ur image.Call reloadData method of the UITableView at the end of the didFinishPickingMediaWithInfo delegate method.
4.The reloadData method will subsequently call the cellForRowAtIndexPath method. In that have a condition like this:
}
where clickedRow is the integer variable which holds the row number clicked by the user in didSelectRowAtIndexPath method.
Hope this helps.