i am new in objective c , i want create alert over save panel to get confirm from user to overwrite exist file or not , like text editor when you save a file in a directory that have same file name alert show over save panel that ask to replace or cancel , when user select cancel alert disappear , when user select replace the alert disappear then save panel. not save panel disappear then alert show. please help
Asked
Active
Viewed 1,019 times
0
-
NSSavePanel has this functionality built-in... – Andrew Madsen Jan 02 '12 at 02:10
-
There's no associated function. It's free. If you use NSSavePanel to let the user pick a location to save a file, it will automatically warn them and ask for confirmation if the path they select already exists. Really, just try it and you'll see... – Andrew Madsen Jan 02 '12 at 02:32
-
thank you for answer , but in my app don't warn me , beside i want the alert show text in my language not in english there i should make alert by code not automatically, i did it but save panel disappear then alert will show . my problem is i want alert appear over save panel – Kosar Jan 02 '12 at 11:47
1 Answers
1
This code is tested and works. It will warn you if the file already exists. The save panel and the file replacement alert will be appear in whatever language Mac OS X is set to use (see screenshot for Japanese example):
- (IBAction)saveTestFile:(id)sender
{
NSString *saveString = [NSString stringWithFormat:@"Hello World, it's %@!", [NSDate date]];
NSSavePanel *savePanel = [NSSavePanel savePanel];
if ([savePanel runModal] == NSFileHandlingPanelOKButton)
{
NSURL *saveURL = [savePanel URL];
NSError *error = nil;
if (![saveString writeToURL:saveURL atomically:YES encoding:NSASCIIStringEncoding error:&error])
{
NSLog(@"Unable to save file: %@", error);
}
}
}

Andrew Madsen
- 21,309
- 5
- 56
- 97
-
thanks i found my error , my error is that i didn't determine filetype and with another procedure i added extension to file. example; when i saved my file with save panel named "my file" then with procedure i add "my file.txt" with extention . next time save panel didn't warn me because "my file" is different from "my file.txt". i want custom alert in my language not default language . example "english" is default but my language is "kurdish" – Kosar Jan 05 '12 at 01:06
-
Glad to hear that you got it working! If Mac OS X itself has been localized into Kurdish, you should be able to enable it in System Preferences. Unfortunately, I'm not sure whether or not OS X has built in support for Kurdish... – Andrew Madsen Jan 05 '12 at 02:24
-
unfortunately OS X hasn't built in support Kurdish but it support kurdish letter, if i want some kurdish interface like nsalert i should do my self, i think is difficult for beginner. – Kosar Jan 09 '12 at 23:59