• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSelector question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSelector question


  • Subject: Re: NSSelector question
  • From: Gian Carlo Cervone <email@hidden>
  • Date: Wed, 4 May 2005 15:23:51 -0400


On May 4, 2005, at 9:12 AM, String Larson wrote:


On May 4, 2005, at 7:24 AM, Ricky Sharp wrote:


On Wednesday, May 04, 2005, at 07:02AM, Gian Carlo Cervone <email@hidden> wrote:


I'm new to xCode (I'm using v. 1.1) and would appreciate any
suggestions on this problem.

If needing to stay with Xcode 1.x, you may want to at least move to version 1.2, but preferably 1.5.


CONTEXT: I'm trying to get a certain method (tableRowDoubleClicked) to
run when an uneditable row in an NSTableView is clicked. I am writing
this project in Java.


IMMEDIATE PROBLEM: my program doesn't seem to recognise the method I've
created. Specifically, NSSelector.implementedByClass is returning
false for the method in question.


QUESTION: Is it enough to define the method and then create a selector
to it, or do you need to somehow register it before it will be seen?
What have I done wrong here or left out?


Here is the code I'm using, from a custom class definition:

==============================
    private NSTableView		fileNames;			/* IBOutlet */
    public  NSSelector 		       theSelector;

theSelector = new NSSelector("tableRowDoubleClicked", new Class[]
{null});

fileNames.setTarget(null);
fileNames.setDoubleAction(theSelector);
System.out.println(theSelector.implementedByClass(DirectoryBrowser.cl ass
));
System.out.println(theSelector.name());
System.out.println(fileNames.target());
System.out.println(fileNames.doubleAction());
try{
System.out.println(theSelector.methodOnClass(DirectoryBrowser.class)) ;
}
catch(NoSuchMethodException e) {
System.out.println("noSuchMethod");
}
=================================


and here is the output:


false tableRowDoubleClicked null NSObjectiveCSelector tableRowDoubleClicked: noSuchMethod


I would have expected the first line to be true since I have a method defined:

	public void tableRowDoubleClicked() { /* IBAction */
System.out.println("Double-clicked!");
	}

I haven't done any Cocoa work with Java, but shouldn't the IBAction methods take a 'sender' parameter? In that case, your selector name would then be tableRowDoubleClicked: (note the colon at the end).


Of course then modify the second parm passed to the NSSelector constructor.
Yes.
eg.
public void generate(Object sender) { /* IBAction */
		doSomething();
    }
Method generate() is connected to a button w/in IB.

This:
http://developer.apple.com/documentation/Cocoa/Conceptual/ LanguageIntegration/Tasks/usingselectors.html#//apple_ref/doc/uid/ 20000869
gives a good example of how to define the selector with the method signature you want.




Thank you both for your ideas. I will upgrade to 1.5.

After reading your replies, I see that my code is in error. The method is no longer an IBAction - that was left in from an earlier try. If I use the connection in IBuilder (note the calling object is an NSTableView, not a button), the method will get called every time someone selects a row, not when they double-click, which is what I really want. I am trying to use NSTableView.setDoubleAction() to get this method called only when someone double-clicks an uneditable row, so that is why I have the method defined as it is, without the sender parameter. Problem is, it doesn't seem to work, and, as the the first line in the example output shows, for some reason, the selector doesn't think that my custom class responds to the message "tableRowDoubleClicked." I have already read the Apple doc page you refer to, and I think the selector is ok, but I still don't seem to have something right.

Thanks again,

Gian Carlo Cervone
Rochester, NY

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSSelector question (From: Gian Carlo Cervone <email@hidden>)
 >Re: NSSelector question (From: Ricky Sharp <email@hidden>)
 >Re: NSSelector question (From: String Larson <email@hidden>)

  • Prev by Date: Re: SearchKit and Spotlight
  • Next by Date: Re: Carbon menu with Cocoa?
  • Previous by thread: Re: NSSelector question
  • Next by thread: NSMenuItemIndex given by NSMenuDidAddItemNotification
  • Index(es):
    • Date
    • Thread