• 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: Enumerating outlets automatically?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enumerating outlets automatically?


  • Subject: Re: Enumerating outlets automatically?
  • From: Boyd Collier <email@hidden>
  • Date: Thu, 6 Nov 2008 12:52:40 -0800

With some trepidation resulting from my lack of expertise, especially relative to those who have already offered suggestions, here is bit of code showing (a somewhat simplified version of) what I do. "self" in the next-to-last line refers to a controller. In the header for the controller, macros are set up corresponding to the tags on the check boxes so that I can then refer to them in the dictionary by easy-to- identify names. Undoubtedly, this way of doing things isn't very sophisticated compared to using bindings, but making the code easy to understand seems like a big benefit.

Boyd


NSMutableDictionary *theIndividTestsDict = [[NSMutableDictionary alloc] initWithCapacity:20];
id anObject;
int theCheckBoxTag;
NSEnumerator *cellEnumerator = [[matrixOfCheckBoxes cells] objectEnumerator];
while (anObject = [cellEnumerator nextObject]) {
theCheckBoxTag = [anObject tag];
[theIndividTestsDict setObject:(id)anObject forKey:[NSNumber numberWithInt:theCheckBoxTag]];
[[theIndividTestsDict objectForKey:[NSNumber numberWithInt:theCheckBoxTag]] setEnabled:YES];
}
[self setIndividualTestsDict:theIndividTestsDict];
[theIndividTestsDict release];







On Nov 6, 2008, at 11:16 AM, Andy Lee wrote:

On Nov 6, 2008, at 12:50 PM, Michael Ash wrote:
On Thu, Nov 6, 2008 at 12:15 PM, Andy Lee <email@hidden> wrote:

Lastly, you could write a proxy object, put it in your nib, and hook
up all of the outlets to it instead. The proxy would intercept all
setFoo: messages by forwarding them to your real object and
simultaneously building a dictionary. This will be sure to only get
real outlets.

I'm not sure I understand -- would the proxy object have outlets to myOutlet1, myOutlet2, etc.?

It wouldn't have outlets in the sense of IBOutlet ivars declared in the header. You would, however, "lie" to IB and tell it that it did have all the outlets you want to manage, then connect them. You would then implement forwarding like so (not tested, buyer beware, etc.):

Ah, I see. When you said setFoo: I was thinking of the setEnabled: message that Graham wanted to send to all the objects, but you meant the setMyOutlet1:, setMyOutlet2:, etc. messages that are (we think) sent when the nib is loaded.


It seems to me that all solutions other than trying to automatically figure out the outlets (and this includes Erik Buck's suggestion to add an array to the nib) are essentially variations on manually specifying the dictionary. Given that choice, I guess I'd prefer just... manually specifying the dictionary. It's very quick and transparent, and omissions are easier to spot than in IB.

--Andy

_______________________________________________

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


_______________________________________________

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: 
 >Enumerating outlets automatically? (From: Graham Cox <email@hidden>)
 >Re: Enumerating outlets automatically? (From: "Michael Ash" <email@hidden>)
 >Re: Enumerating outlets automatically? (From: Andy Lee <email@hidden>)
 >Re: Enumerating outlets automatically? (From: "Michael Ash" <email@hidden>)
 >Re: Enumerating outlets automatically? (From: Andy Lee <email@hidden>)

  • Prev by Date: Re: dragging an image to Photoshop dock tile
  • Next by Date: Re: About OS Shutting down / Restarting
  • Previous by thread: Re: Enumerating outlets automatically?
  • Next by thread: Re: Enumerating outlets automatically?
  • Index(es):
    • Date
    • Thread