IOS尝试将uiimagepicker中的图像添加到uicollectionview单元格中

时间:2014-10-16 01:04:36

标签: ios objective-c uiimagepickercontroller uicollectionviewcell

我尝试通过imagepicker加载图像并将其插入到数组中,以便在调用imagepicker后将其推送到新的UIcollectionview单元格,如下所示:

- (void) imagePickerController: (UIImagePickerController *) picker
 didFinishPickingMediaWithInfo: (NSDictionary *) info {

    testPicture = [info valueForKey:UIImagePickerControllerOriginalImage];

    [self dismissViewControllerAnimated:YES completion:nil];   

    NSLog(@"%@", testPicture);    
下面是我试图将图像加载到新数组的地方:

NSArray *newData =  [NSArray arrayWithObjects: testPicture , nil];
 [self.collectionView performBatchUpdates:^{
        int resultsSize = [self.data count]; //data is the previous array of data
        [self.data addObjectsFromArray:newData];
        NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
        for (int i = resultsSize; i < resultsSize + newData.count; i++)
        {
            [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
        }
        [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];

     }
}

如果我从之前加载的数组中调用图像,它就可以工作:

NSArray *newData =  [NSArray arrayWithObjects: @"my_image.jpeg" , nil];

否则我会收到长度错误,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

UIImagePickerControllerOriginalImage的值 指定用户选择的原始未剪切图像。

此键的值是UIImage对象。

它不是图像路径,可能是你的collectionView绑定了错误的数据类型。