Ok, So i want to add the ability to undo certain actions in my app. I was going to create a way to do it, with my own protocals or something, but then I found out about NSUndoManager
. I would like to use the built in foundation way, but I can't seem to figure it out. I need to undo multiple dice rolling, so if I could store the previous rolls, as objects in an NSArray
, would probably be the best. I could use an NSMutableString
, but the array would be preferred.
Then I know you can shake to undo, but I would rather have a button. These has been giving me the most trouble. I've included my attempts below. None of those have worked. Any help would be appreciated.
In viewDidLoad:
undoManager = [[NSUndoManager alloc] init];
Then in the method that rolls the dice, I tried:
[[undoManager prepareWithInvocationTarget:self] undoButton];
[[undoManager prepareWithInvocationTarget:self]
[[undoManager prepareWithInvocationTarget:self] setString:[NSString stringWithFormat:@"%i", dice1num]];
setStrings:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%i", dice1num]
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num],
[NSString stringWithFormat:@"%i", dice1num], nil]];
[[undoManager prepareWithInvocationTarget:@selector()];
[undoManager setActionName:@"A roll"];
And then here is the IBAction that links to the undo button:
-(IBAction)undoButton{
[undoManager undo];
}
Thanks in advance