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
  • Re: D/Objective-C 64bit Jacob Carlborg via Digitalmars-d-announce
    • Re: D/Objective-C 64bi... Christian Schneider via Digitalmars-d-announce
      • Re: D/Objective-C ... Jacob Carlborg via Digitalmars-d-announce
        • Re: D/Objectiv... Christian Schneider via Digitalmars-d-announce
          • Re: D/Obje... Jacob Carlborg via Digitalmars-d-announce
            • Re: D... John Colvin via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
            • Re: D... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Michel Fortin via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce
              • R... Jacob Carlborg via Digitalmars-d-announce
              • R... Christian Schneider via Digitalmars-d-announce

Reply via email to