It compiles because NO == nil == NULL == 0.

I shouldn't have posted the silly example which doesn't work in most cases.

how about this typed in mail:

@interface NSView (MYGroupEnable)

/// Enable all controls nested within the receiver
- (void)enableSubviews
{
   for(NSView *currentView in [self subviews])
   {
      if([currentView respondsToSelector:@selector(setEnabled:)])
      {
         [currentView setEnabled:YES];
      }
      else
      {
         [currentView enableSubviews];
      }
   }
}


/// Disable all controls nested within the receiver
- (void)disableSubviews
{
   for(NSView *currentView in [self subviews])
   {
      if([currentView respondsToSelector:@selector(setEnabled:)])
      {
         [currentView setEnabled:NO];
      }
      else
      {
         [currentView disableSubviews];
      }
   }
}

@end

On Jun 19, 2009, at 3:23 AM, Graham Cox wrote:


On 19/06/2009, at 3:59 AM, Erik Buck wrote:

use
[[myBox subviews] makeObjectPerformSelector:@selector(setEnabled:) withObject:NO];

or similar.


Are you certain that works? 'NO' isn't an object, so I didn't think you could use -makeObjectsPerformSelector:withObject: in this fashion - or is there some magic available that isn't mentioned in the docs? The docs appear to state explicitly that the single argument to the selector must be type id. However it does seem to compile without complaint, though I'm not sure why... If this is permitted, does it work with rects, points, etc?

Alternatively you can use: [[box subviews] setValue:[NSNumber numberWithBool:NO] forKey:@"enabled"]; since KVC converts to scalars as needed.

Another problem here is that setEnabled: only works on NSControls or derivative, not NSViews. So you'd have to be certain that all your subviews were controls, otherwise it will throw with an unknown property error when it hits the first non-control view. Or you could implement -setEnabled for NSView in a category.

--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to