D/Objective-C 64bit
Jacob Carlborg via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Mon Nov 3 06:16:04 PST 2014
On 2014-11-03 09:51, Christian Schneider wrote:
> I have a question regarding selectors. I wanted to set a double-click
> action in the tableview example. Currently i get the selector like this:
>
>
> objc.runtime.SEL doubleAction =
> cast(objc.runtime.SEL)&AppDelegate.doubleClickAction ;
> demoTableView.setDoubleAction(doubleAction) ;
>
>
> Is this the recommended/right way to do it?
No, have a look at the tests for selectors [1]. I'm not sure if you need
to cast it to "SEL". Try just using "auto":
auto doubleAction = &AppDelegate.doubleClickAction;
> Then the double-click action looks like this:
>
>
> void doubleClickAction(NSObject sender) {
>
> NSTableView tableView = cast(NSTableView)sender ;
>
> if (sender is demoTableView) {
> NSInteger clickedRow = demoTableView.clickedRow() ;
> Item item = cast(Item)_applications.objectAtIndex(clickedRow) ;
> NSWorkspace.sharedWorkspace().launchApplication(item.itemDisplayName()) ;
> }
> }
>
>
> I would expect to be using an ObjcObject instead of an NSObject here,
> but this does not compile. The signature of the target action seems to
> be irrelevant, it may have no or more parameters. I guess this is just
> ok and the expected behavior.
Hmm, that sounds strange. What exact errors do you get?
[1]
https://github.com/jacob-carlborg/dmd/blob/d-objc/test/runnable/objc/objc_selector.d
--
/Jacob Carlborg
More information about the Digitalmars-d-announce
mailing list