What I have is a document based app, but it automatically saves everything - I 
don't want to ask the user. So I'm saving all my documents in 
closeAllDocumentsWithDelegate. It's working pretty good, the only major hassle 
is the app doesn't die on machine shutdown, presumably because I wasn't calling 
didCloseAllSelector.

I agree the whole setup is pretty confusing but after ponding it extensively, I 
think it is more or less sensible, given the need for the RunLoop and so on. 
(albeit, poorly documented).

I'm not sure what you mean you can "invoke the method easily enough".

Maybe the right way to do it is with NSInvocation. But knowing what I know 
about objective-c, I can't see how setArgument:atIndex: would be able to know 
that the second argument is a BOOL which is one byte. Maybe it does know and it 
all just works.




________________________________
From: Graham Cox <[email protected]>
To: Chris Idou <[email protected]>
Cc: [email protected]
Sent: Thursday, 1 October, 2009 11:42:05 AM
Subject: Re: NSDocumentController didCloseAllSelector


On 01/10/2009, at 11:00 AM, Chris Idou wrote:

> The doco for closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo: 
> says that it should call
> the didCloseAllSelector. How would one do that? This is what I am doing:

Chris, this stuff is a right old mess. No wonder you're confused.

It says *it* will call that method if all documents are closed. You don't 
necessarily have to call anything - looking at the byzantine interactions 
between all these methods all I can say is, if you can avoid it, do so!

What do you want to do? Unless you're overriding - 
(void)canCloseDocumentWithDelegate:(id)delegate 
shouldCloseSelector:(SEL)shouldCloseSelector contextInfo:(void *)contextInfo
to do something in a non-standard way there's nothing to do. If you are 
overriding it, you need to handle the whole kit-n-kaboodle, including 
presenting the alert to the user and saving the document to disk, and finally 
invoking the mysterious callback selector.

I can't actually see an easy way to invoke the callback selector with the 
signature as given - you need to pass it the document (self), a BOOL and the 
contextInfo. You can invoke the method directly on the delegate easily enough, 
but since you're supposed to use the callback supplied, that might not work. 
The only way I can see to do it is to create an NSInvocation with the selector, 
set each argument and call invokeWithTarget: passing the delegate.

Someone else might have a brighter idea - this seems very involved and badly 
thought-out.

--Graham


      
__________________________________________________________________________________
Get more done like never before with Yahoo!7 Mail.
Learn more: http://au.overview.mail.yahoo.com/
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to