Skip to content

Commit

Permalink
fix crash when deleting files on iPad
Browse files Browse the repository at this point in the history
  • Loading branch information
zydeco committed May 26, 2022
1 parent aa52115 commit 1cfc5bd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Mini vMac/InsertDiskViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSString *filePath = [self fileAtIndexPath:indexPath];
if ([UIAlertController class]) {
[self askDeleteFile:filePath];
[self askDeleteFile:filePath sourceView:[tableView cellForRowAtIndexPath:indexPath]];
} else {
[self deleteFile:filePath];
}
Expand Down Expand Up @@ -323,14 +323,15 @@ - (void)deleteFile:(NSString*)filePath {
}
}

- (void)askDeleteFile:(NSString*)filePath {
- (void)askDeleteFile:(NSString*)filePath sourceView:(UIView*)sourceView {
NSString *fileName = filePath.lastPathComponent;
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete %@? This operation cannot be undone.", nil), fileName];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Delete File", nil) message:message preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleCancel handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Delete", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[self deleteFile:filePath];
}]];
alertController.popoverPresentationController.sourceView = sourceView;
[self presentViewController:alertController animated:YES completion:nil];
}

Expand Down Expand Up @@ -696,7 +697,7 @@ - (void)rename:(id)sender {
}

- (void)delete:(id)sender {
[self.controller askDeleteFile:self.filePath];
[self.controller askDeleteFile:self.filePath sourceView:self];
}

@end

0 comments on commit 1cfc5bd

Please sign in to comment.