【发布时间】:2013-11-08 06:42:28
【问题描述】:
我有一个应用程序,在 UIViewcontroller 上有一个 takePhoto UIButton,使用户可以使用 imagePickerController 拍照。然后我希望将照片放在UITableView。
照片部分有效,出于测试目的,我将图像显示在UIImage photoImageView.image
我添加了UITableView 委托,然后UITable 被称为photoTable,而单元格被称为photoCell。我试图找出下面的代码来将图像添加到表格中但没有成功。非常感谢任何帮助。
- (IBAction)takePhoto:(id)sender
{
[self startCameraControllerFromViewController: self usingDelegate: self];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image;
image = (UIImage *)
[info valueForKey:UIImagePickerControllerOriginalImage];
photoImageView.image=image;
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:nil];
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate
{
if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil)) return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
- (UITableViewCell*)tableView:(UITableView*)photoTable cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* CellIdentifier = @"photoCell";
UITableViewCell* cell = [photoTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell.imageView.image = [UIImage imageNamed:@"nameOfImage.jpg"];
return cell;
}
【问题讨论】:
-
if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; }
标签: ios objective-c uitableview uiimagepickercontroller