【问题标题】:Save Image after UICollectionView closes in iOS在 iOS 中关闭 UICollectionView 后保存图像
【发布时间】:2023-03-20 20:41:01
【问题描述】:

我的 UICollectionView 有一个按钮,可以打开相机并将该图像保存到 UICollectionView

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
[self.images addObject:image];
//NSLog([NSString stringWithFormat:@"%d",[self.images count]]);
NSIndexPath *ip = [NSIndexPath indexPathForRow:[self.images count] inSection:0];
[picker dismissViewControllerAnimated:YES completion:nil];
[self.galleryView reloadData];
IDMPhoto *photo;

photo = [IDMPhoto photoWithImage:image];
photo.caption = @"Sample";
[photos addObject:photo];

}

现在我的问题是我有一个完成按钮,如何将图像保存到图库并添加(文件名+编号)。顺便说一下 UICollectionView 嵌入在 PopOver 中

最后,是否有可能当我打开 UICollectionView 时,它会检索图库中的图像。

我希望你能帮助我.....谢谢! :D

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller uicollectionview popover


    【解决方案1】:

    如果您的 Done 按钮也嵌入在弹出框中(我假设是这样),只需使用委托并在您的弹出框 ViewController 接口文件中创建一个协议。让呈现的ViewController 成为该协议的委托,然后在您完成选择图像时触发该委托方法。

    类似这样的:

    @protocol MyCollectionImagePickerDelegate
        -(void)doneSelectingImage:(UIImage *)image;
    @end
    
    @interface MyCollectionViewPopoverController : UIViewController {
        __unsafe_unretained id <MyCollectionImagePickerDelegate> _delegate;
    }
    
    @property (nonatomic, assign) id <MyCollectionImagePickerDelegate> delegate;
    

    然后在:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { 
        [_delegate doneSelectingImage:image];
    }
    

    在您展示的 VC 类中,您只需实现该方法并使用底层集合执行您需要的操作(我假设为NSArray)。

    【讨论】:

    • 您好,感谢您的建议,我会先尝试一下 :) 如果有效,我会通知您
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2017-03-03
    • 1970-01-01
    • 2016-09-17
    • 2023-03-19
    相关资源
    最近更新 更多