开发者

When a cocoa method wants a selector as a parameter, how do I express this in ruby?

In this tutorial for sheet programming in cocoa, I am told to invoke the following method:

[[alert beginSheetModalForWindow:[searchField window] 
    modalDelegate:self 
    didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) 
    contextInfo:nil];

I have written this as follows in ruby,

alert.beginSheetModalForWindow(self.window, 
    modalDelegate:self,
    didEndSelector: :alertDidEnd,
    contextInfo:nil)

Of course, the didEndSelector part is wrong. Later in my code I have a method alertDidEnd, which takes returnCode and contextInfo as arguments. When I looked at self.methods I noticed that the method is liste开发者_StackOverflow社区d as alertDidEnd:returnCode:contextInfo:. In the sample code above an '@' is used to mark the selector. This is accomplished in Macruby with a symbol, but in this case the symbol would contain colons, which is not allowed. How should I represent this method name as a symbol? I wasn't able to find this information on my own, where should I have looked that I didn't?

Thanks!


As noted in the MacRuby docs, symbols are bridged with selectors. So you'd do:

alert.beginSheetModalForWindow(self.window, 
    modalDelegate:self,
    didEndSelector: :'alertDidEnd:returnCode:contextInfo:',
    contextInfo:nil)


Have you tried using a Symbol? It seems to work in RubyCocoa.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜