0

我到处寻找这个问题的答案,我有一个相机屏幕,你可以在上面拍照,然后照片需要存储在某个地方,然后可以稍后从 tableview 访问。

4

1 回答 1

2

将 a 中捕获的图像存储UIImagePickerController在 anNSArray中是有效的。

你可以有这样的东西:

/* 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];
}
于 2012-09-26T01:04:13.907 回答