• 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: Bind button title to Boolean
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bind button title to Boolean


  • Subject: Re: Bind button title to Boolean
  • From: Steve Christensen <email@hidden>
  • Date: Mon, 27 Oct 2008 07:33:27 -0700

On Oct 27, 2008, at 3:32 AM, Trygve Inda wrote:

How can I bind a button title to a Boolean but have a custom title for each
state? For example, I have a BOOL isRunning, if YES, my button should read
"Stop Running" else "Start Running".


I can't really do this with an alternate title since when the button is
pushed and temporarily held down, the title should not change as it is a
normal push "pill" button.

How about something like this? Whenever isRunning changes, it triggers an update of the button's title.



+ (void) initialize { ...

    [self setKeys:[NSArray arrayWithObject:@"isRunning"]
        triggerChangeNotificationsForDependentKey:@"buttonTitle"];

    ...
}


- (NSString*) buttonTitle { return [self isRunning] ? @"Stop Running" : @"Start Running"; }


- (BOOL) isRunning { return _isRunning; }

- (void) setIsRunning:(BOOL)isRunning
{
    [self willChangeValueForKey:@"isRunning"];
    _isRunning = isRunning;
    [self didChangeValueForKey:@"isRunning"];
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Bind button title to Boolean (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: Finding out that a volume is going away before it does
  • Next by Date: Re: IKImageBrowserView only horizontal scrolling
  • Previous by thread: Re: Bind button title to Boolean
  • Next by thread: [MEET] Amsterdam CocoaHeads Thursday 10/30 7:00pm
  • Index(es):
    • Date
    • Thread