문제

I have tried using this:

1) Create the file NSOpenPanelExtension.h that contains:

#import <Cocoa/Cocoa.h>

@interface NSOpenPanel (Extension)

- (void)setCancelButtonTitle:(NSString *)newTitle;

@end

2) Create the file NSOpenPanelExtension.m that contains:

#import "NSOpenPanelExtension.h"

@implementation NSOpenPanel (Extension)

- (void)setCancelButtonTitle:(NSString *)newTitle
{
NSRect oldFrame = [_cancelButton frame];

[_cancelButton setTitle:newTitle];
[_cancelButton sizeToFit];

NSRect newFrame = [_cancelButton frame];
float delta = oldFrame.size.width - newFrame.size.width;

[_cancelButton setFrameOrigin:NSMakePoint(oldFrame.origin.x + delta,
oldFrame.origin.y)];
}

@end

3) Use it where you need it:

#import "NSOpenPanelExtension.h"
...
NSOpenPanel *panel = [NSOpenPanel openPanel];  
[panel setCancelButtonTitle:@"NO!"];

But when I [panel setCancelButtonTitle:@"NO!"] my NSOpenPanel crashes and this appears on my console (along with the usual errors and codes):

*** Assertion failure in -[NSRemoteOpenPanel forwardingTargetForSelector:], /SourceCache/RemoteViewServices/RemoteViewServices-80.5/NSRemoteSavePanel.m:1975
An uncaught exception was raised
sandboxed save/open panel presently acting unlike a panel

What's wrong? How can I change the cancel button title of a NSOpenPanel? Example code would be appreciated!

도움이 되었습니까?

해결책

This problem can be connected with changes in NSOpenPanel mentioned in App Sandbox Design Guide:

Certain NSOpenPanel and NSSavePanel methods behave differently when App Sandbox is enabled for your app:

You cannot invoke the OK button using the ok: method.

You cannot rewrite the user’s selection using the panel:userEnteredFilename:confirmed: method from the NSOpenSavePanelDelegate protocol.

In addition, the effective, runtime inheritance path for the NSOpenPanel and NSSavePanel classes is different with App Sandbox...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top