Presenting view controllers on detached view controllers is discouraged

Source: Internet
Author: User
Modal View Controllers
About Modal View controllers



1. When you present a modal view controller, the system creates a parent-child relationship between the view controller th At did the presenting and the View controller is presented. Specifically, the view controller that did the presenting updates its Modalviewcontroller Ed (child) View Controller. Similarly, the presented view controller updates its parentviewcontroller, the view controller th At presented it.



2. A modal view controller that presents another modal view controller has valid objects into both its parentviewcontroller and Modalviewcontroller properties. If the user cancels the current operation, your could remove all objects in the chain by dismissing the "a" modally nted View Controller. In the other words, dismissing a modal view controller dismisses does only this view controller but any view controllers it pre sented modally.


onfiguring the presentation Style for Modal views



For the IPAD applications, you can present content modally using several different styles. View controllers use the ' value in their modalpresentationstyle ' to determine their appearance when presented modal Ly.


presenting a View Controller modally

To present a view controller modally, your must do the Following:create the view controller your want to present. Set the Modaltransitionstyle property of the view controller to the desired value. Assign a delegate object where appropriate. (The delegate is used primarily from System view controllers to notify your code when the view controller was ready to being dis Missed. ) call the PresentModalViewController:animated:method of the "Current View" controller, passing in the view Contro Ller you want to present modally.



[Plain] View Plain copy print? -  (void) add: (ID) sender {      // create the root view  controller for the navigation controller      // the  new view controller configures a cancel and done button for  the      // navigation bar.       recipeaddviewcontroller *addcontroller = [[recipeaddviewcontroller alloc]                           initwithnibname:@ "Recipeaddview"  bundle:nil];          // Configure the RecipeAddViewController. In this case,  it reports any      // changes to a custom delegate  object.      addController.delegate = self;          // Create the navigation controller and present it  modally.      uinavigationcontroller *navigationcontroller = [[ uinavigationcontroller alloc]                                  initWithRootViewController:addController];      [self  presentmodalviewcontroller:navigationcontroller animated:yes];           // the navigation controller is now owned by the current  view controller      // and the root view  Controller is owned by the navigation controller,      // so both objects should  be released to prevent over-retention.      [navigationcontroller  release];      [addController release];  

dismissing a Modal View Controller
1. When it comes the dismiss a modal view controller, the preferred approach are to let the parent view controller do t He dismissing.

2. In a delegate-based model, the view controller being presented modally must define APROTOCOL for it delegate to Implem Ent. The protocol defines methods that are called by the modal View controller into response to specific actions. The delegate is then responsible for implementing this methods and providing an appropriate.

This use is delegation to manage interactions with a modal view controller has some key advantages over the other techniques: The delegate object has the opportunity to validate or incorporate changes from the modal view controller before so view Controller is dismissed. The use of a delegate promotes better encapsulation because the modal view controller does does have to know anything about The parent object that presented it. This is enables you to reuse the modal view controller in other parts of your.


[Plain]View Plain copy print? @protocol recipeadddelegate <NSObject>//recipe = = nil on cancel-(void) Recipeaddviewcontroller: (Recipeaddview   Controller *) Recipeaddviewcontroller didaddrecipe: (myrecipe *) recipe; @end
[Plain] View Plain copy print? -  (void) Recipeaddviewcontroller: (recipeaddviewcontroller *) recipeaddviewcontroller                        Didaddrecipe: (recipe *) recipe {      if  (Recipe)  {         // Add the recipe to the recipes  controller.         int recipecount = [recipescontroller  countOfRecipes];         UITableView *tableView =  [self tableview];         [recipescontroller insertobject: recipe inrecipesatindex:recipecount];             [ tableview reloaddata];      }      [self dismissmodalviewcontrolleranimated:yes];  }  
presenting Standard System Modal View Controllers

Turn from: http://blog.csdn.net/nerohoop/article/details/7034348

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.