- addSubView
- pushViewController
- presentModalViewController
Feature | addSubView / insertSubView | pushViewController | presentModalViewController |
Usage | It is typically use to create view heirarchy programmatically. A view heirarchy will consist of multiple subviews that make up different components in the view. Each sub view will has its own draw and animation handling. Each sub view also has its own event handling. Alternatively, view heirarchy can be created using Interface Builder. | In many IPhone application, the user will need to go through different pages of form / view to complete a specific workflow for a task. Typically, pushViewController is used to step the user through the different pages to complete the task. It is usually work with navigation controller. Push view controller will create the visual effect of push page left to right. | In some IPhone application, while performing a task, the user will need to complete a self-contained subtask before he can continue the task. Modal view mechanism can be used to accomplish the subtask function. By default, the present modal viewController will slide a set of controls from bottom to top to the current view. The modal view need to be dismissed before the user can continue with the current view. |
Compatibility with navigationController tabBarController | Usually the subview will be added to the top of the current view, hence cover the navigation bar. The toolbar may also be covered depending on the size of the subview. The subview can use setFrame to position it below the navigation controller. Eg: [self.view setFrame:CGRectMake(0,60,320,400)]; | Work well with tabBarController, navigationController | Both controllers will be hidden from the modal view. Except for partialCurl transitionStyle. which the NavigationBar will still be visible. |
Return back from the added view | Has to implement return mechanism. | Can have automatic back button created if the root Controller is navigation controller and the back barButtonItem is created in the root navigation controller. ** For default back button to work, each view must has title setted. | Has to implement return mechanism. |
Sample code: Add newViewController | [self.viewController.view addSubView: newViewController.view]; | [self.viewController pushViewController: newViewController]; | [self.viewController presentModalViewController: newViewController]; |
Sample code: Remove newViewController | [self.view removeFromSuperView]; | [self.viewController popViewController Animated: YES]; | [self dismissModalViewController Animated: YES]; |