• 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
NSArray Selection code works on Tiger, but not Panther
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArray Selection code works on Tiger, but not Panther


  • Subject: NSArray Selection code works on Tiger, but not Panther
  • From: Dan Price <email@hidden>
  • Date: Tue, 6 Jun 2006 11:05:43 +0100 (BST)

I hope you guys can help me with this - it's driving me nuts.

I'm working on a graphics app that supports a hierarchical scene-graph and multiple shape-selection. The view class maintains an NSMutableArray, mSelectedShapes, that maintains a list of pointers to all the currently 'selected' shape-objects, independant of the main shape list. Shapes can be selected in the view class or via the scenegraph (an NSOutlineView) and draw themselves as 'selected' in the view. mSelectedShapes is initied at startup as:

mSelectedShapes = [[NSMutableArray alloc] init];

The accessors in the view are:

- (void)setSelectedShapes:(NSArray *)selection
{
    if (selection == nil) // no selection so clear list
    {
        for (int i = 0; i < [mSelectedShapes count]; i++)
        {
            ShapeNode *s = [mSelectedShapes objectAtIndex: i];
            [s setSelected: NO]; // deselect prevously selected shapes
        }
        [mSelectedShapes removeAllObjects]; // remove all shapes from the list
    }
    else // there was a selection of one or more shapes
    {
        for (int i = 0; i < [selection count]; i++)
        {
            ShapeNode *s = [selection objectAtIndex: i];

            // only add shape if it's not in the list
            if (![mSelectedShapes containsObject: s])
            {
                [s setSelected: YES];
                [mSelectedShapes addObject: s];
            }
        }
    }

    [self setNeedsDisplay: YES];
}

- (NSMutableArray *)selectedShapes {
    return mSelectedShapes;
}

To select one shape for example: self setSelectedShapes: [NSArray arrayWithObject: <<shape to select>>]];
To clear the selection: [self setSelectedShapes: nil];

Several UI-controls are bound to these accessors so that they can keep in-sync with the selection. This all works fine on Tiger, but on Panther, I get an NSCFArray 'index (0) out of bounds' error in the console when clearing the selection and it screws up the whole works. I'm using XCode 2.2.x on the Tiger mac, but the panther machine doesn't have any dev tools so it's hard to debug. What am I doing wrong?
 Send instant messages to your online friends http://uk.messenger.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: crash when using notification center and self
  • Next by Date: Java VM version
  • Previous by thread: NSColorPanel: Obtaining the color spectrum view
  • Next by thread: Java VM version
  • Index(es):
    • Date
    • Thread