开发者

Objective-C overwriting file alert

In my application, I want the user to be able to select a file/location to save data to. Thus, I'm using the following code:

NSSavePanel *newSavePanel = [NSSavePanel savePanel];
NSArray *newArray = [[NSArray alloc] initWithObjects:@"txt", nil]; //example file type
[newSavePanel setAllowedFileTypes:newArray];

NSInteger newInt;

newInt = [newSavePanel runModal];

My problem is that I want the save panel to alert the user and ask for confirmat开发者_如何学Pythonion to overwite if the file already exists. To do this, do I need to implement the delegate method panel:userEnteredFilename:confirmed: in which I place a [[NSFileManager defaultManager] fileExistsAtPath:] message, at which point I create an NSAlert, or is there a better way to go about doing this?

I haven't actually had time to test this, so if the behavior is already implemented in NSSavePanel, could someone let me know?


I may be wrong, but I think you get that behavior by default.
*edit - * yeah you get that out of the box, I used your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜