• 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 Behaviors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSButton Behaviors


  • Subject: Re: NSButton Behaviors
  • From: Erik Buck <email@hidden>
  • Date: Fri, 28 Sep 2007 22:10:45 -0400

I had what I suspect was a similar problem: In an editor interface, users could press buttons to specify a selection tool. Some selection tools were simple and some complex. There could only ever be one selection tool in effect at any given moment, so a matrix of radio buttons for selection tools was ideal. However, I needed to indicate which selection tool was in effect with a different icon that the icon use to indicate the selection tool was merely available. If you click the button for the tool that is currently in effect, the result is no tool in effect. With all this behavior, a simple matrix of radio buttons is insufficient. I think this is very similar to your needs.

I put the buttons in a matrix in "Track" mode and used the following code in the action method that was sent by pressing any of the selection tool buttons: (The code ensures exclusive selection and works if the matrix itself sends the action or if the contained buttons send the action)


- (IBAction)takeCurrentEditorSelectionToolFromRepresentedObject:(id) sender
{
id cell;


if([sender respondsToSelector:@selector(representedObject)] && [sender respondsToSelector:@selector(state)])
{ // sender provides all of the information needed
cell = sender;
}
else if([sender respondsToSelector:@selector(selectedCell)])
{ // sender can provide a cell that may have the needed information
cell = [sender selectedCell];


      if([sender respondsToSelector:@selector(cells)])
      {  // make selection exclusive or empty
         NSArray        *allCells = [sender cells];
         int            i;

         for(i = [allCells count] - 1; i >= 0; i--)
         {
            if(cell != [allCells objectAtIndex:i])
            {
               [[allCells objectAtIndex:i] setState:NSOffState];
            }
         }
      }
   }

   if(NSOffState == [cell state])
   {
      [self setCurrentSelectionTool:nil];
   }
   else
   {
      [self setCurrentSelectionTool:[cell representedObject]];
   }
}

_______________________________________________

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


  • Prev by Date: NSControlTextDidChangeNotification fires only once upon setting delegate
  • Next by Date: Re: NSControlTextDidChangeNotification fires only once upon setting delegate
  • Previous by thread: Re: NSButton Behaviors
  • Next by thread: NSControlTextDidChangeNotification fires only once upon setting delegate
  • Index(es):
    • Date
    • Thread