Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSMatrix...I don't get it

NSMatrix...I don't get it
Thread Tools
Bi@tch
Forum Regular
Join Date: Apr 2002
Location: Canada
Status: Offline
Reply With Quote
Dec 6, 2002, 05:37 PM
 
Someone give me an example of how to use NSMatrix. I don't understand how to make it work. A sample application's code would be just fine but I can't find any on the internet.

Thank you
     
macrophyllum
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Dec 6, 2002, 09:45 PM
 
Here is a very basic sample of an action when the user selects a radio button in an NSMatrix:

-(IBAction) toggleOnLaunchOptions:(NSMatrix *)sender {
//called when user clicks on one of the radio buttons in the general view of prefs
//the rows are set with tags in IB
[defaults setInteger:[sender selectedRow] forKey:@"OnLaunchOptions"];

}
     
Bi@tch  (op)
Forum Regular
Join Date: Apr 2002
Location: Canada
Status: Offline
Reply With Quote
Dec 7, 2002, 03:06 PM
 
Maybe if I tell you what I'm trying to do, it'll be a little easier.

I have this grid that's drawn. Now when the user clicks the grid I want a matrice to return me in what row and col the event happended.

I have found this method:

- (BOOL)getRow:(int *)row column:(int *)col forPoint:(NSPoint)aPoint;

The only thing that's stopping me from using it right now is (int *).

This doesn't seem to be the right way

[matrice getrow:row column:col forPoint:aPoint];

it doesn't set the values to the row and col variables...
     
Amorph
Dedicated MacNNer
Join Date: Mar 2001
Location: Iowa City, IA
Status: Offline
Reply With Quote
Dec 7, 2002, 04:03 PM
 
Disclaimer: I'm more of a C guy than Objective-C.

That said:

If you're passing to a function that expects int * parameters, you pass the addresses of ints:

int row, column;

[matrice getRow:&row column:&column forPoint:aPoint];

Note the & (address of) operator, which evaluates to a pointer to the variable following it. Now getRow:column:forPoint has some actual variables to work with, so when the method returns row and column should hold the values you want.

This is, I believe, the correct way to call the method you found. Whether it's the right way to do what you want done, I can't say.
James

"I grew up. Then I got better." - Sea Wasp
     
Bi@tch  (op)
Forum Regular
Join Date: Apr 2002
Location: Canada
Status: Offline
Reply With Quote
Dec 7, 2002, 05:49 PM
 
Doesn't seem to work sadly.

Doing This:

int row, column;
NSLog(@"%i,%i", row, column);
[matrice getRow:&row column:&column forPoint:[theEvent locationInWindow]];
NSLog(@"%i,%i", row, column);

The output was:

2002-12-07 16:47:55.298 Testinggrounds[2717] -1559812360,2480128
2002-12-07 16:47:55.298 Testinggrounds[2717] -1559812360,2480128

So you see, nothing happended to the variable.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 7, 2002, 10:10 PM
 
-[NSMatrix getRow:column:forPoint:] expects a point in the receiver's coordinate system. I'm not sure, but it might not set anything if the point you give is outside of the receiver's bounds. In order to use this method, it would have to be [matrice getrow:&row column:&column forPoint:[matrice convertPoint:[theEvent locationInWindow] fromView:nil]].
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Bi@tch  (op)
Forum Regular
Join Date: Apr 2002
Location: Canada
Status: Offline
Reply With Quote
Dec 9, 2002, 06:24 PM
 
Ok it works fine now thanks to all. The problem I had is that you cannot use it if you have an NSView on top of it.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:44 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,