Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement deletion of an item. #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

crousselle
Copy link

No description provided.

@crousselle crousselle changed the title Improve handling of the toolbar and status bar when hiding the controls in MHGalleryImageViewController. Implement deletion of an item. Jun 8, 2015
@mythodeia mythodeia mentioned this pull request Jun 8, 2015
@JesseScott
Copy link

I've implemented the changes in this request manually, and would recommend the following method in your delegate to actually handle the deletion of the asset:

- (void)removeItemAtIndex:(NSInteger)index { MHGalleryItem *item = [self itemForIndex:index]; NSURL *assetURL = [NSURL URLWithString:item.URLString]; if (assetURL == nil) { return; }
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL] options:nil]; if (result.count > 0) { PHAsset *phAsset = result.firstObject; if ((phAsset != nil) && ([phAsset canPerformEditOperation:PHAssetEditOperationDelete])) { [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ [PHAssetChangeRequest deleteAssets:@[phAsset]]; } completionHandler:^(BOOL success, NSError *error){ if ((!success) && (error != nil)){ NSLog(@"Error deleting asset: %@", [error description]); } }]; } } }

@crousselle
Copy link
Author

@JesseScott My local implementation of removeItemAtIndex:(NSInteger)index does not deal with any PHAsset but with some model specific to my application.
I implemented this as a delegate callback so that people can handle the removal no matter what the objects they are using.
The datasource deletion is just here to maintain the data presented by the controller (IE the galleryItems array in this case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants