I have a loop set to copy files to a directory, however, when a file already exists at the destination, a UIAlertView displays prompting the user to overwrite, skip, cancel, etc. My question is, how can I pause the loop until the UIAlertView is dismissed, at which point the next (if any) UIAlertView will be displayed.
The loop code looks like this:
for (NSString *fileInArray in selectedFiles) {
[self copyFile:fileInArray destination:[self.path stringByAppendingPathComponent:[fileInArray lastPathComponent]]];
}
The paths are stored in an NSArray as NSStrings, the NSArray is created in another method (copy/move) this is the paste method.
This is the method to paste files (for the copy function).
- (void) copyFile:(NSString *)input destination:(NSString *) output{
NSFileManager *copyManager = [NSFileManager defaultManager];
NSError *error;
if ([copyManager fileExistsAtPath:output]){
RIButtonItem *overwriteItem = [RIButtonItem itemWithLabel:@"Overwrite" action:^{
NSError *removeError;
[copyManager removeItemAtPath:output error:&removeError];
if (removeError){
[self displayError:[NSString stringWithFormat:@"There was a problem overwriting the file '%@'. %@", [output lastPathComponent], [removeError localizedDescription]]];
}
}];
RIButtonItem *cancelItem = [RIButtonItem itemWithLabel:@"Skip" action:^{
}];
RIButtonItem *renameItem = [RIButtonItem itemWithLabel:@"Rename" action:^{
}];
UIAlertView *fileExistsAlert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"A file already exists at the destination matching this file." cancelButtonItem:cancelItem otherButtonItems:overwriteItem, renameItem, nil];
[fileExistsAlert show];
}
[copyManager copyItemAtPath:input toPath:output error:&error];
if (error){
[self displayError:[error localizedDescription]];
}
Currently, the first UIAlertView displays for about 1 second and then is hidden, at which point the interface becomes grey, as if it's disabled and no more UIAlertViews appear. Using the latest iOS SDK.