我到处都试图找到这个问题的答案,我有一个相机屏幕,你拍照片然后需要将照片存储在某处,然后可以从桌面视图中访问。
答案 0 :(得分:2)
将UIImagePickerController
中捕获的图像存储在NSArray
中有效。
你可以这样:
/* ViewController.h */
@interface ViewController : UIViewController <UIImagePickerControllerDelegate>
@property (nonatomic, strong) UIImagePickerController *imagePicker;
@property (nonatomic, strong) NSMutableArray *photos;
/* ViewController.m */
@synthesize imagePicker = _imagePicker;
@synthesize photos = _photos;
// initialize imagePicker
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
self.imagePicker = imagePicker;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self.photos addObject:selectedImage];
}
编辑:要在表格视图中查看数组中的图像,您可以这样:
// I'm assuming you only have 1 section for the table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.photos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get / instantiate cell
// This will use the default imageView in a UITableViewCell.
cell.imageView.image = [self.photos objectAtIndex:indexPath.row];
}