Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-07-2011, 10:15 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 8
Cori is on a distinguished road
Smile How to separate consecutive INSERTs into separate transaction/UNDO/REDO?

I'm trying to find a way on how to separate two INSERTs into entity/table that was done consecutively, to be seen as two separate transaction and should be UNDOne individually, also.

I got a method that does 2 INSERTs into a table/entity consecutively. When an [moc undo] is executed, the 2 inserts are of course UNDOne together. How can I make the 2 INSERTs as separate transactions? I tried the beginUndoGrouping/endUndoGrouping but wasn't able to make it work. Also tried the setGroupsByEvent, I got error when saving the MOC.

Below is a simplified code snippet. Thanks so much for your help!!

//-------------------------------------- METHODS IN CONTROLLER ABC
-(IBAction) undoInsert:(id) sender{
//[moc.UndoManager undo];
[moc undo];
}

-(void) insertNumber:(NSNotification*)notification {
double theNumber = [[…. userInfo] objectForKey:aNumber];
Data *newRow = [NSEntityDescription insertNewObjectForEntityForName:@"DATA" inManagedObjectContext:self.thisMOC];
newRow.VALUE = [NSNumber numberWithDouble:theNumber];
newRow.TYPE = @"A";
//...
if (condition) {
[thisMOC save:&error];
}
}

-(void) insertTotal:(NSNotification*)notification {
//i tried here the beginUndoGrouping/endUndoGrouping to separate this INSERT but it still gets UNDOne together
//[thisMOC setGroupsByEvent:NO];
//[thisMOC.undoManager beginUndoGrouping];
//...
double theNumber = [[…. userInfo] objectForKey:aNumber];
Data *newRow = [NSEntityDescription insertNewObjectForEntityForName:@"DATA" inManagedObjectContext:self.thisMOC];
newRow.VALUE = [NSNumber numberWithDouble:theNumber];
newRow.TYPE = @"T";
//...

//[thisMOC.undoManager endUndoGrouping];
//[thisMOC setGroupsByEvent:YES];
[thisMOC save:&error];
}
//-------------------------------------- end of METHODS IN CONTROLLER ABC

//--------------------------------------- METHODS IN CONTROLLER XYZ
//Note: the Controllers ABC and XYZ are totally independent/unaware of each other, XYZ passes data only thru Notification.
-(IBAction) doInsertNumber:(id) sender {
//aNumber is given a value somewhere, is passed as user info dictionary numberDict

[[NSNotificationCenter defaultCenter]
postNotificationName:@"InsertNumber" object:self userInfo:numberDict];
//..

}

-(IBAction) doInsertTotal:(id) sender {
//these two INSERTs gets UNDOne together, I need to separate the UNDO for these 2 numbers

//aNumber, xNumber are given values somewhere, packaged into dictionary numberDict
[[NSNotificationCenter defaultCenter]
postNotificationName:@"InsertNumber" object:self userInfo:numberDict];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"InsertTotal" object:self userInfo:numberDict];
}
//-------------------------------------- end of METHODS IN CONTROLLER XYZ
Cori is offline   Reply With Quote
Reply

Bookmarks

Tags
transaction processing, undo/redo

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 382
8 members and 374 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, UMAD, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:55 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0