user4567987
user4567987

Reputation: 3

Undoing a button Click

I have a button (named randomGenerator) that everytime you press it, it generates random statements. How can I create a button (undoButton) that when clicked will undo the action that randomGenerator called and take you back to the statement before it? So basically I want to undo a button action method based of a button click:

-(void) randomGeneratorClicked {

      //generate a random statement

}

-(void) undoButtonClicked {

    //undo the action that [self randomGeneratorClicked] has done
}

Upvotes: 0

Views: 53

Answers (1)

Justin Voss
Justin Voss

Reputation: 6384

It sounds like you should read about NSUndoManager.

When you generate a new random value, you can use the registerUndoWithTarget:selector:object: method to store the previous value.

When the user taps the undo button, you can call the undo method on the undo manager to step backwards through the undo history.

Upvotes: 3

Related Questions