How To Use Undo On iPhone?

In this application we will see , how to Main View Controller displays information (title, author, and copyright date) about a book. The user can edit this information by tapping Edit in the navigation bar.

Step 1: Create a Window base application using template . Give the application name “UndoApplication” .

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Now we’ll add Table view controller class to the project. Choose New file -> Select cocoa touch classes group and then select UITableViewController subclass. Give the name “MainViewController”, and add corresponding .xib file. Add other class UIViewController subclass, give the name of the class “EditingViewController” and the corresponding .xib file. Add one more class using NSObject give the name of the class “Book”.

Step 4: In the AppDelegate.h file we have added the  NavigationController in the file.

 

 

 

Step 5: Double click the MainWindow.xib file and open it to the Interface Builder. Select view controller and change the class name into the MainViewController.Now select Undo Application App Delegate, and bring up connection inspector. Select navigationController to the NavigationController. Select View window and bring up Attributes Inspector and change the Nib name into the MainViewController. Save the MainWindow.xib file and go back to the Xcode.

Step 6: Make the following changes in the AppDelegate.m file.

 

 

 

Step 7: In the MainViewController.h, we have added NSDateFormatter and NSUndoManager,make the following changes:

 

 

 

Step 8: Double click MainViewController.xib file, open it to the Interface Builder. Select the table view and bring up Attribute Inspector, change the style into the grouped. Save the MainViewController.xib file and go back to the Xcode.

Step 9: Make the following changes in the MainViewController.m file.

 

 

 

Step 10: Now make the following changes in the EditingViewController.h file, we have added in this file UIDatePicker, and UITextField.

 

 

 

Step 11: Double click your EditingView.xib file and open it to the Interface Builder. Drag the datepicker from the library and place it to the view window and drag text field from the library and place it on to the datepicker . Select File’s Owner icon and bring up connection inspector select datePicker to the Picker and text field to the Round Style Text Field. Now save the EditingView.xib file and go back to the Xcode.

Step 12: In the EditingViewController.m file make the following changes:

 

 

 

Step 13: Now compile and run the application in the simulator.

You can downloaded SourceCode from here UndoApplication 2

Leave a Comment: