• 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: NSButton reports reverse state
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSButton reports reverse state


  • Subject: Re: NSButton reports reverse state
  • From: Fritz Anderson <email@hidden>
  • Date: Mon, 16 Jun 2008 14:33:47 -0500

The cocoa-dev list is the place for Cocoa questions; this is the list for the Xcode development tools. That said:

On 16 Jun 2008, at 4:45 AM, mirage_3d wrote:

i have implemented an NSMatrix of checkboxes and had an outlet that points to it in IB. in my code i have changed the appearance of the buttons as well as their states in awakeFromNib. when i check the buttons' states in my action however, the buttons report the inverse state to what they really should. i used NSOffButton and NSOnButton constants for setting and checking, and the values are correct. but when i check the buttons' states later on they just report the opposite. i'm lost as to where to look to track what's going on or debug. any ideas as to why this might happen ?

i even tried to flip the button's state inside the switch/case and nslog reports the same opposite behavior.

here's my IBAction...

- (IBAction)setCheckBoxOptions:(id)sender
{
// NSLog(@"setOptions: Checkbox: %d was called by: %@", [[sender selectedCell] tag], sender);
// NSButton *optionBox = [sender selectedCell];
NSButton *optionBox = [sender selectedCell];

switch ([optionBox state]) {
case NSOffState:
NSLog(@"optionBox \"%@\": %d", [optionBox title], [optionBox state]);
// [optionBox setState:NSOnState];
NSLog(@"case 1: setOptions: optionBox: %d to %d", [optionBox tag], NSOnState);
break;
case NSOnState:
NSLog(@"optionBox \"%@\": %d", [optionBox title], [optionBox state]);
// [optionBox setState:NSOffState];
NSLog(@"case 2: setOptions: optionBox: %d to %d", [optionBox tag], NSOffState);
break;
case NSMixedState:
default:
// [optionBox setState:NSOffState];
NSLog(@"case 3: setOptions: Mixed optionBox: %d to %d", [optionBox tag], NSOffState);
break;
}
NSLog(@"NSOnState = %d", NSOnState);
NSLog(@"NSOffState = %d", NSOffState);
}

The "state" property isn't what you appear to think it means. By the time you get to an action method for an NSCheckbox (or a matrix that keeps checkbox state), the state of the button has already changed. Click on an "off" checkbox, and in the action method, it will report the state as "on."

By the way, the selectedCell method will return an NSCell (it happens in this case to be an NSButtonCell), not an NSButton.  

— F

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

This email sent to email@hidden

References: 
 >NSButton reports reverse state (From: mirage_3d <email@hidden>)

  • Prev by Date: Re: Shark question
  • Next by Date: Re: aggregate targets and build configurations
  • Previous by thread: NSButton reports reverse state
  • Next by thread: OpenMP in Xcode
  • Index(es):
    • Date
    • Thread