beginSheet:替代块? [英] beginSheet: block alternative?
本文介绍了beginSheet:替代块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Snow Leopard不会引入一些替代旧的beginSheet:方法的方法,该方法允许使用块来完成整理工作吗?我不喜欢在其他回调方法中使用它。
Didn't Snow Leopard introduce some alternative to the old beginSheet: method that allows using a block to do the finishing stuff? I don't like having it in another callback method.
推荐答案
没关系。我在这两个站点上找到了所需的内容:
Never mind. I found what I'm looking for at these two sites:
http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html ,
http://www.cocoabuilder。 com / archive / cocoa / 281058-sheets-blocks-and-garbage-collector.html
实际上,这是代码,并且完全兼容同时具有GC和非GC的系统:
In fact, this is the code, and it's fully compatible with both GC and non-GC:
@implementation NSApplication (SheetAdditions)
- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow didEndBlock:(void (^)(NSInteger returnCode))block
{
[self beginSheet:sheet
modalForWindow:docWindow
modalDelegate:self
didEndSelector:@selector(my_blockSheetDidEnd:returnCode:contextInfo:)
contextInfo:Block_copy(block)];
}
- (void)my_blockSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
void (^block)(NSInteger returnCode) = contextInfo;
block(returnCode);
Block_release(block);
}
@end
这篇关于beginSheet:替代块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文