Trouble with setTarget, toolbars, and saving
Trouble with setTarget, toolbars, and saving
- Subject: Trouble with setTarget, toolbars, and saving
- From: Chad Armstrong <email@hidden>
- Date: Mon, 25 Aug 2003 12:07:47 -0500
I'm trying to implement a save feature into the toolbar, but I'm
running into some complications. The program saves just fine when I
either save from the menu, or even attach a button to the interface and
connect either of them to the MyController I've created in IB. This
MyController also has its own associated .h and .m files.
Here is some associated code.
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *item = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
MyController *controller = [[MyController alloc] init];
if ( [itemIdentifier isEqualToString:@"Save"] )
{
// Configuration code for "Save"
[item setLabel:@"Save"];
[item setToolTip: @"Save"];
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"Save"]];
[item setTarget: controller];
[item setAction:@selector(mySaveDocumentTo:)];
}
.
.
.
}
When mySaveDocumentTo is called, it brings up an individual save box,
instead or rolling down as a sheet like it normally does when I select
Save from the File menu. It seems to be able to step through the save
process, but it cannot save atomically. So when it runs into the
following code, it returns NO and doesn't save.
if ([image writeToFile:[sheet filename] atomically:NO]==NO)
{
NSRunAlertPanel(nil, @"Cannot save file '%@': %s", nil, nil,
nil, [sheet filename], strerror(errno));
}
Another concept I'm trying to figure out with Cocoa is how the
MyController exists and interacts with the other classes of the
program. I'm guessing since that IB has an 'instance' of MyController,
that it has essentially been declared and initialized (in a sense). Is
it possible for my toolbar to access this particular instance of the
controller? About the only way it seems like I can somewhat
communicate between the toolbar and the controller is to create a new
controller, and that might be what is mixing things up. As I've
mentioned, the code works properly when called from a button in the
interface or from the Save menu item.
Any ideas what I might be missing here, or should I ultimately ditch
the idea? Thanks.
Chad Armstrong
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.