• 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
indexed accessors and NSArrayControllers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

indexed accessors and NSArrayControllers


  • Subject: indexed accessors and NSArrayControllers
  • From: Nicolas Berloquin <email@hidden>
  • Date: Fri, 2 Apr 2004 19:59:16 +0200

Hello !


I started using data bindings and NSArrayControllers not long ago, and now I'm having
a problem that I don't understand.

here's what I'm doing:
- I have a window with a tableview and some textfields that are bound, via an NSArrayController
to a field of NBTransferManager class :

(snip)
@interface NBTransferManager : NSObject {
NSMutableArray *pendingPieces;
}

- (void) setPendingPieces:(NSMutableArray *)array;
- (NSMutableArray *) pendingPieces;
- (void) insertObject:(id)anObject inPendingPiecesAtIndex:(unsigned int)index;
- (void) removeObjectFromPendingPiecesAtIndex:(unsigned int)index;
@end

pendingPieces is an array of NBPieces *, which has things like:

@interface NBPiece : NSObject {
int numAvailable;
int numBlocksRemaining;
int numBlocksUnqueued;
}
and all the getter/setters for those fields.

so the array controller is bound to pendingPieces.
All the fields in my window are bound via the NSArrayController's content array to:
arrangedObjects.@count
arrangedObjects.numAvailable
arrangedObjects.numBlocksRemaining

etc etc...

Alright, now the window gets updated when I add objects to pending pieces, and when
I modify things like numAvailable.

Now, I'm having the following error :
when I call, from NBTransferManager :

[self removeObjectFromPendingPiecesAtIndex: [pendingPieces indexOfObject: piece]];

I get the following error right at the call :
[pendingPieces removeObjectAtIndex: index];
inside removeObjectFromPendingPiecesAtIndex: (see below)

*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)

but when I do:
[pendingPieces removeObjectAtIndex: [pendingPieces indexOfObject: piece]];
instead, no error shows (besides the fields in my window not getting updated, of course).

I checked inside the method :
- (void) removeObjectFromPendingPiecesAtIndex:(unsigned int)index
{
[pendingPieces removeObjectAtIndex: index]; <----- here !
}
With a single element, to see if the array was fine, and if the piece was fine, both are ok.
[pendingPieces count] returns 1
[pendingPieces indexOfObject: piece] returns 0

It seems that someone is double-removing the same object behind my back,
but I can't understand why !!

thanks for your help ;-)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: indexed accessors and NSArrayControllers (followup)
      • From: Nicolas Berloquin <email@hidden>
  • Prev by Date: Re: Is the internet avaliable question
  • Next by Date: Re: Threads and locks
  • Previous by thread: Re: Resource file length?
  • Next by thread: Re: indexed accessors and NSArrayControllers (followup)
  • Index(es):
    • Date
    • Thread