On 24/02/2012, at 12:58 AM, William Squires wrote:

>  I have a custom view with an NSBox containing an NSMatrix of button cells 
> (radio buttons) When I created the NSMatrix, I told it I wanted 3 of them, 
> but in the view hierarchy, I can see the NSMatrix under the NSBox, but it has 
> 4 button cells under it, not the three I asked for - Is this an Xcode/IB 
> screw-up, or do NSMatrix's always add one extra element when making a group 
> of radio buttons? Should I delete the matrix and try again? When I vertically 
> resize the matrix, I always see three cells, so I don't think there's one 
> hidden under there.
>  Also, even though I set the tag for each button cell (the top one is 0, the 
> next one down is 1, etc...), when I connect them to my
> 
> -(IBAction)baseChanged:(id)sender
> {
> int choice = [sender tag];
> switch (choice)
>  {
>  case 0: // number base is 16 - hexadecimal
>          NSLog(@"user chose hexadecimal");
>          ...
>          break;
> 
>  case 1: // number base is 2 - binary
>          NSLog(@"user chose binary");
>          ...
>          break;
> 
>  case 2: // number base is 10 - decimal
>          NSLog(@"user chose decimal");
>          ...
>          break;
>  }
> self.numberBase = choice;
> }
> 
> I always get, "user chose hexadecimal"! :( (all the buttons generate an 
> action, so it's not that...)
>  Am I supposed to connect the NSMatrix to the action, and not the individual 
> cells? If so, how do I ask for the cell's tag value?


I'm not sure why you're getting 1 more than you apparently asked for - it 
should be the number, no more. 

To set the tag for each cell in the matrix, you need to go through them in IB 
and set the tag, they are not automatically inserted, and all default to zero. 
I usually set the target/action of the entire matrix and use the tag of the 
cell to determine which cell was selected. So, instead of [sender tag], I use 
[[sender selectedCell] tag].

Also, it doesn't matter much here, but you really should be using type 
NSInteger instead of int everywhere.

--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to