Re: (void *)contextInfo
Re: (void *)contextInfo
- Subject: Re: (void *)contextInfo
- From: Markus Spoettl <email@hidden>
- Date: Tue, 12 Jan 2010 21:19:44 +0100
On Jan 12, 2010, at 8:51 PM, Rainer Standke wrote:
> Here is the code that displays the sheet:
>
> NSArray *theContextInfo = [[NSArray alloc] init];
> theContextInfo = [NSArray arrayWithObject:objTBD];
>
>
> [NSApp beginSheet: alertWindow
> modalForWindow: [selfwindowForSheet]
> modalDelegate: self
> didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
> contextInfo: theContextInfo];
>
>
> and here is the code that runs eventually after the sheet has been dismissed:
>
> - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
> {
>
> NSLog(@"Sheet End");
> NSLog(@"%@", [contextInfo class]);
> [sheet orderOut:self];
> }
>
>
> The contextinfo's class is logged as NSConcreteMutableData. How can I get back to the array? Why is contextinfo considered to be of class void in the signature?
>
> What am I missing? (Another newbie thing I suspect...)
The first array is created (and you own it) but the second assignment one throws away the reference (so you leak the just created array). Also, the second reference (which gets passed to your didEndSheet: message) is likely garbage by the time the sheet returns because you didn't retain the array.
You probably want something like this:
NSArray *theContextInfo = [[NSArray alloc] initWithObject:objTBD];
[... your sheet code here];
- (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
NSArray *array = (NSArray *)contextInfo;
[... do something with the array]
// you need to release it when done because you own it.
[array release];
NSLog(@"Sheet End");
NSLog(@"%@", [contextInfo class]);
[sheet orderOut:self];
}
Regards
Markus
--
__________________________________________
Markus Spoettl
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden