Reputation: 1123
I get the following error from the alert sheet code below when the user hits the default button:
-[NSRectSet objectForKey:]: unrecognized selector sent to instance 0x400876300
Btw, the code works fine in Snow Leopard but the problem comes up in Lion.
NSMutableDictionary * extrasDict = [[NSMutableDictionary alloc] init];
[extrasDict setObject:@"http://www.google.com" forKey:@"link"];
NSAlert * alert = [NSAlert alertWithMessageText:@"Published Successfully"
defaultButton:@"View Collage on Facebook"
alternateButton:nil
otherButton:@"Cancel"
informativeTextWithFormat:@"Successfully published to Facebook."];
[alert beginSheetModalForWindow:myWindow
modalDelegate:self
didEndSelector:@selector(publishedSuccessfullyDidEnd:returnCode:contextInfo:)
contextInfo:extrasDict];
- (void)publishedSuccessfullyDidEnd:(NSAlert *)alert
returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo {
if (returnCode == NSAlertDefaultReturn) {
[[NSWorkspace sharedWorkspace] openURL:
[NSURL URLWithString:[(NSDictionary*)contextInfo objectForKey:@"link"]]];
}
}
Upvotes: 2
Views: 3564
Reputation: 26
I have executed your coding part. It's working well. Check the remaining part of the coding.
Upvotes: 0
Reputation: 17218
If you're using garbage collection, store extrasDict
in an instance variable – anywhere, doesn't matter – so it isn't released at the end of the run loop. You need the dictionary to stick around until the didEndSelector
can act on it.
Upvotes: 3