• 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: One IBAction, multiple results from multiple methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One IBAction, multiple results from multiple methods


  • Subject: Re: One IBAction, multiple results from multiple methods
  • From: "Peter Ilberg" <email@hidden>
  • Date: Thu, 26 Feb 2009 09:16:49 -0600

On Thu, 26 Feb 2009 08:49:57 -0600, I. Savant <email@hidden> wrote:

- (IBAction)seek:(id)sender
{
        // We have to figure out speed and direction
	BOOL forward;
	int factor;

	// The sender (based on its tag) tells us this ...
	int tag = [sender tag];  // or NSInteger tag = [sender tag];
	switch (case)
	{
		case 1001: // seek back
		forward = NO;
		factor = 1;
		break;

		case 1002: // seek back FAST
		forward = NO;
		factor = 2;
		break;

		case 1003: // seek forward
		forward = YES;
		factor = 1;
		break;

		case 1004: // seek forward FAST
		forward = YES;
		factor = 2;
		break;

		default:
		forward = YES;
		factor = 1;
		break;
	}

	// Now tell the media controller what to do
	[mediaController seek:forward withFactor:factor];

	// Maybe update the UI
	[self updateUI];

        // Maybe do some more complicated things with other arguments ...
}

Depending on your scenario, you might be able to encode the different cases into bitfields. The above function then turns into something like this:

typedef union {
	int tag;
	struct {
		unsigned	forward:1;
		unsigned	factor:4;
	} fields;
} MyCases;

- (IBAction)seek:(id)sender
{
	MyCases cases;

	cases.tag = [sender tag];
	[mediaController seek:cases.fields.forward withFactor:cases.fields.factor];
	[self updateUI];
}

You have to write a small utility to figure out which tag value encodes
which field options, but that's a small price to pay. Alternatively, you
can encode bitfields manually:

#define FORWARD_FIELD_MASK   0x0010
#define FACTOR_FIELD_MASK    0x000F

And do the bit-shifting/masking yourself.

--- Peter
_______________________________________________

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


  • Follow-Ups:
    • Re: One IBAction, multiple results from multiple methods
      • From: "I. Savant" <email@hidden>
References: 
 >One IBAction, multiple results from multiple methods (From: Walker Argendeli <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: "I. Savant" <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: Klaus Backert <email@hidden>)
 >Re: One IBAction, multiple results from multiple methods (From: "I. Savant" <email@hidden>)

  • Prev by Date: Using NSTableView without Nib files
  • Next by Date: Re: NSTextView very slow, any remedies?
  • Previous by thread: Re: One IBAction, multiple results from multiple methods
  • Next by thread: Re: One IBAction, multiple results from multiple methods
  • Index(es):
    • Date
    • Thread