Skip to content

Implement deletion of an item. - #102

Open
crousselle wants to merge 1 commit into
mariohahn:masterfrom
crousselle:deletion
Open

Implement deletion of an item.#102
crousselle wants to merge 1 commit into
mariohahn:masterfrom
crousselle:deletion

Conversation

@crousselle

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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