Tuesday, April 19, 2011

Creating Modal View

In a typical Windows environment, modal window is a child or popup window where user can not press on any control on the parent window before complete and close the child or popup modal window.

For IPhone or IPad application, modal view behave the same. Sometime it is neccessary to popup a modal view to the user for data entry or other action view which the user has to complete the data entry view before the user can proceed to other part of the application.

The following steps outline how such modal view can be acheived:

1. Create a UIViewController subclass, by New File -> Cocoa   touch -> UIViewController subclass.
    Ensure that the "With XIB for user interface" option is selected.
    eg.  create a UIViewController subclass -> ModalController

2. Use interface builder to create the needed UI in the created ModalController.

3. Add the following modal view invocation code in the appropiate section:

ModalController* modal = [[ModalController alloc] initWithNibName:Nil bundle:Nil];
[modal setModalTransitionStyle:UIModalTransitionStylePartialCurl];  // this will determine how the modal transition in
[modal setModalPresentationStyle:UIModalPresentationFullScreen];  // this will how the modal will be presented
[self.navigationController presentModalViewController:modal animated:YES];

4. Add the following modal view removal code in the appropiate section, eg. link to the exit button of the ModalController:

- (IBAction) backToMain: (id) sender {
    [self dismissModalViewControllerAnimated:YES];

No comments:

Post a Comment