很简单,我想使用UIImagePicker
拍摄照片并将其放入NSMutableArray
。我在下面的代码如下。相机部件工作正常,出于测试目的,图像显示在名为 photoImageView 的UIImage
中。但是我似乎无法将图像添加到数组中。任何帮助都感激不尽。
@property (nonatomic, retain) NSMutableArray *photos;
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
photoImageView.image=photoTaken;
[photos addObject:[UIImage photoTaken];
[picker dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:1)
您是否已将数组实例化到某处(例如viewDidLoad
):
self.photos = [NSMutableArray alloc] init];
答案 1 :(得分:1)
1)你是否正在初始化照片NSMutableArray?有时addObject:在尝试将对象插入NULL NSArray时不会抛出错误。
2)
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *photoTaken = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
if (photoTaken)
{
photoImageView.image=photoTaken;
[photos addObject:photoTaken];
}else{
NSLog(@"Selected photo is NULL");
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
答案 2 :(得分:1)
添加到(Ian L)
后修改如下 [photos addObject: photoTaken];
答案 3 :(得分:1)
photoTaken
已经被实例化为UIImage
个对象。无需这样做:
[photos addObject : [UIImage photoTaken]];
只需这样做:
[photos addObject : photoTaken];