|
|
NSMatrix...I don't get it
|
|
|
|
Forum Regular
Join Date: Apr 2002
Location: Canada
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
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"];
}
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Apr 2002
Location: Canada
Status:
Offline
|
|
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...
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Mar 2001
Location: Iowa City, IA
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Apr 2002
Location: Canada
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
-[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'."
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Apr 2002
Location: Canada
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|