• 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: Deletes Object on Remove option
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deletes Object on Remove option


  • Subject: Re: Deletes Object on Remove option
  • From: BK <email@hidden>
  • Date: Sun, 2 Apr 2006 12:59:57 -0700


On Apr 2, 2006, at 11:46 AM, mmalcolm crawford wrote:


On Apr 1, 2006, at 12:47 PM, email@hidden wrote:

For a contentSet binding, I have the "Deletes Object on Remove" option set. I'd like to know if there is a way to change this setting programmatically?

Re-establish the binding...

NSDictionary *info = [arrayController infoForBinding:@"contentSet"];
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:
[info objectForKey:NSOptionsKey]];
BOOL deletesOnRemove =
[((NSNumber *)[options objectForKey:NSDeletesObjectsOnRemoveBindingsOption]) boolValue];
deletesOnRemove = 1-deletesOnRemove;
[options setObject:[NSNumber numberWithBool:deletesOnRemove]
forKey:NSDeletesObjectsOnRemoveBindingsOption];

[arrayController bind:@"contentSet"
toObject:[info objectForKey:NSObservedObjectKey]
withKeyPath:[info objectForKey:NSObservedKeyPathKey]
options:options];


mmalc

Thanks, that seemed to re-establish the bindings. However, I noticed something odd: I don't get the same behavior as when I uncheck "Deletes Object on Remove" in IB. Below is the code I'm using. The method moveObjectsInArrangedObjectsFromIndexes is from some Apple sample code for dragging and dropping rows within the same table view, something I'm trying to do. If I use the code below, nothing happens when I drag and drop within the same table view. However, if I comment out setDeletesOnRemove and uncheck "Deletes Object on Remove" in IB, it works! Any hints as to where to look next would be appreciated.
Thanks,
Bill


-(void) setDeletesOnRemove:(NSArrayController*)inArrayController deletesOnRemove:(BOOL)inDeletesOnRemove
{
NSDictionary *info = [inArrayController infoForBinding:@"contentSet"];
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:[info objectForKey:NSOptionsKey]];
BOOL deletesOnRemove = [((NSNumber *)[options objectForKey:NSDeletesObjectsOnRemoveBindingsOption]) boolValue];
if( inDeletesOnRemove != deletesOnRemove ) {
[options setObject:[NSNumber numberWithBool:inDeletesOnRemove] forKey:NSDeletesObjectsOnRemoveBindingsOption];

[inArrayController bind:@"contentSet"
toObject:[info objectForKey:NSObservedObjectKey]
withKeyPath:[info objectForKey:NSObservedKeyPathKey]
options:options];
}
}



-(void) moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet toIndex:(unsigned int)insertIndex
{
[self setDeletesOnRemove:timeLineController deletesOnRemove:NO];
NSArray *objects = [timeLineController arrangedObjects];
int index = [indexSet lastIndex];

int aboveInsertIndexCount = 0;
id object;
int removeIndex;

while (NSNotFound != index)
{
if (index >= insertIndex) {
removeIndex = index + aboveInsertIndexCount;
aboveInsertIndexCount += 1;
} else {
removeIndex = index;
insertIndex -= 1;
}
object = [objects objectAtIndex:removeIndex];
[timeLineController removeObjectAtArrangedObjectIndex:removeIndex];
[timeLineController insertObject:object atArrangedObjectIndex:insertIndex];

index = [indexSet indexLessThanIndex:index];
}
[self setDeletesOnRemove:timeLineController deletesOnRemove:YES];
}


_______________________________________________
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


  • Follow-Ups:
    • Re: Deletes Object on Remove option
      • From: mmalcolm crawford <email@hidden>
References: 
 >Deletes Object on Remove option (From: email@hidden)
 >Re: Deletes Object on Remove option (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: Extracting file name & path from NSOpenPanel
  • Next by Date: Re: Weirdness in my PowerBook... Now reproducible
  • Previous by thread: Re: Deletes Object on Remove option
  • Next by thread: Re: Deletes Object on Remove option
  • Index(es):
    • Date
    • Thread