Monday, July 23, 2018

#1 2010-11-04 07:01:01 am

RIRedinPA
Member
From:: Philadelphia
Registered: 2003-11-12
Posts: 237
Website

Obj-c: Multiple NSMatrix - determining which one is being clicked on..

I am sure this is a simple answer that I am not seeing. My app is for multiple users. I have two matrixes of radio buttons that point to one method. (It's a gender selection). How do I determine which matrix was being used. I've tried this:

-(IBAction)radioButton:(id)sender {
    NSMatrix *radioMatrix = sender;
    NSButtonCell *radioButton = [radioMatrix selectedCell];
    NSLog(@"%@", [radioMatrix Name]);
}

in various ways, radiomatrix.name, radioMatrix Object ID, sender.name, etc. but they all fail. How do I get the properties of a matrix?


Filed under: NSMatrix

Offline

 

#2 2010-11-04 07:35:19 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11499
Website

Re: Obj-c: Multiple NSMatrix - determining which one is being clicked on..

Hi,

the simplest way is to tag (an integer) the matrices in Interface Builder,
for example assign 0 to the first matrix, 1 to the second etc.

Define an enumeration, this is optional but increases the readability of the code

[code]enum {
    kMyFirstMatrix = 0,
    kMySecondMatrix,
    kMyThridMatrix,
};
typedef NSUInteger MatrixIdentifier;[/code]
then it's very easy to identify the matrices

Applescript:


-(IBAction)radioButton:(id)sender {
MatrixIdentifier identifier = [sender tag];
if (identifier == kMyFirstMatrix)
// do something;
else if (identifier == kMySecondMatrix)
// do something else;
}


regards

Stefan

Offline

 

#3 2010-11-04 08:16:01 am

RIRedinPA
Member
From:: Philadelphia
Registered: 2003-11-12
Posts: 237
Website

Re: Obj-c: Multiple NSMatrix - determining which one is being clicked on..

I solved it using tag:

if ([radioMatrix tag] == 0) {
//do something coming from matrix 1
} else {
//do something coming from matrix 2
}

Offline

 

#4 2010-11-04 08:17:23 am

RIRedinPA
Member
From:: Philadelphia
Registered: 2003-11-12
Posts: 237
Website

Re: Obj-c: Multiple NSMatrix - determining which one is being clicked on..

Hi Stefan...

Should have checked here before I posted. I figured it out exactly as you suggested. Question though, why can I set Name and Object ID in IB but not access those properties?

Rereading your post, are you discouraging setting the tag in IB for matrices? (Which is what I did)

Last edited by RIRedinPA (2010-11-04 08:18:44 am)

Offline

 

#5 2010-11-04 08:30:53 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11499
Website

Re: Obj-c: Multiple NSMatrix - determining which one is being clicked on..

RIRedinPA wrote:

Rereading your post, are you discouraging setting the tag in IB for matrices? (Which is what I did)


No, why? I just prefer better identifiers than a literal number.

All information in the AppleScript tab in Interface Builder are not accessible from Objective-C
Read NSMatrix Class Reference to see the possible methods


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)