0
我已經到處試圖尋找這個問題的答案,我有一個攝像頭畫面,讓您拍攝照片,然後將照片需要在某個地方,然後可以從實現代碼如下稍後訪問存儲。將捕獲的圖像存儲在數組中?
我已經到處試圖尋找這個問題的答案,我有一個攝像頭畫面,讓您拍攝照片,然後將照片需要在某個地方,然後可以從實現代碼如下稍後訪問存儲。將捕獲的圖像存儲在數組中?
將在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];
}
完美!還有一個問題,你會用什麼代碼在tableview中顯示數組中的圖像? –
也只是想補充一點,當我這樣做達到15點聲望,我將投票你的答案! –
@AndrewGierens我更新了我的答案,包括代碼表視圖來顯示圖像。 HTH :) – neilvillareal