gpt4 book ai didi

objective-c - 将 NSAlert beginSheetModalForWindow 与 contextInfo 结合使用

转载 作者:行者123 更新时间:2023-12-03 16:33:03 27 4
gpt4 key购买 nike

当用户点击默认按钮时,我从下面的警报表代码中收到以下错误:

-[NSRectSet objectForKey:]: unrecognized selector sent to instance 0x400876300

顺便说一句,代码在 Snow Leopard 中运行良好,但在 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"]]];
}
}

最佳答案

如果您使用垃圾收集,请将 extrasDict 存储在实例变量中 - 任何地方,都没关系 - 因此它不会在运行循环结束时释放。您需要保留字典,直到 didEndSelector 可以对其进行操作。

关于objective-c - 将 NSAlert beginSheetModalForWindow 与 contextInfo 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6855573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com