2012-09-25 49 views

回答

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]; 
} 
+0

完美!還有一個問題,你會用什麼代碼在tableview中顯示數組中的圖像? –

+0

也只是想補充一點,當我這樣做達到15點聲望,我將投票你的答案! –

+0

@AndrewGierens我更新了我的答案,包括代碼表視圖來顯示圖像。 HTH :) – neilvillareal

相關問題