[iOS base Control-6.12.2] Modal

Source: Internet
Author: User

A. Concept1. Can also be used to switch the Controller 2. If actionsheet except push, there is another kind of controller switching mode, that is modal any controller can be shown in the form of modal modal default effect: The new controller from the bottom of the screen to drill up, Until the previous controller is covered.

Display the controller in the form of modal
-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) flag completion: (void (^) ( void)) Completion

Shut down the modal controller.
-(void) dismissviewcontrolleranimated: (BOOL) flag completion: (void (^) (void)) completion; B. Use1. Use code to demonstrate modal controller: Presentviewcontroller modal interface: Dismissviewcontroller source controller and modal controller relationship
    • Rootviewcontroller has always been the source controller.
    • The system will replace the view itself
    • The source controller has an attribute pointing to the modal controller: Presentedviewcontroller (so the modal controller will not be destroyed)
Use Navigationcontroller to wrap the modal controller and add the previous navigation bar Appdelegate:
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2     //Override point for customization after application launch.3    4     //Set Window5Self.window =[[UIWindow alloc] init];6Self.window.backgroundColor =[Uicolor Graycolor];7Self.window.frame =[[UIScreen mainscreen] bounds];8 [Self.window makekeyandvisible];9    Ten     //Create a UIView OneUiviewcontroller *viewcontroller =[[Uiviewcontroller alloc] init]; AViewController.view.backgroundColor =[Uicolor Redcolor]; -UIButton *button = [[UIButton alloc] Initwithframe:cgrectmake ( -, -, $, -)]; -[Button Settitle:@"Eject modal"Forstate:uicontrolstatenormal]; the [button addtarget:self action: @selector (Poptomodal) forcontrolevents:uicontroleventtouchupinside]; -     - [Viewcontroller.view Addsubview:button]; -Self.window.rootViewController =Viewcontroller; +     -     returnYES; + } A  at- (void) Poptomodal { -Uiviewcontroller *viewcontroller =Self.window.rootViewController; -     -     //then create a uiview to switch -Uiviewcontroller *modalviewcontroller =[[Uiviewcontroller alloc] init]; -ModalViewController.view.backgroundColor =[Uicolor Bluecolor]; in     -     //Create a Navigationcontroller to wrap toUinavigationcontroller *navicontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:modalviewcontroller]; +ModalViewController.navigationItem.title =@"Blue"; -     the     //Switch to Navigationcontroller *[Viewcontroller Presentviewcontroller:navicontroller Animated:yes completion:^{ $NSLog (@"Complete modal switch");Panax Notoginseng     }]; -}
2. Use Storyboard (1) to drag into the controller and connect using " modal"To jump, instead of the previous" Push "(2) to close the modal, bounce Greenviewcontroller:
 1 -(ibaction) GoBack: (Uibarbuttonitem *) Sender { 2  //  off modal  3  //  1. You can use your own  4  //  [self dismissviewcontrolleranimated:yes completion:nil];  5  6  //   2. You can also use the previous layer of navigation controller  7   [Self.navigationcontroller Dismissviewcontrolleranimated:yes Completion:nil] ; 8 } 
(3) data transfer problem on modal connection A. Pass: Use the Segue controller "red" controller to transmit the string to the "green" controller:
1 /*2 * Transfer data here to the modal controller3 * Pass, use the controller4 */5- (void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {6     //1. Get modal steering controller, here is the middle of the navigation controller7Uinavigationcontroller *nvcontroller = (Uinavigationcontroller *) Segue.destinationviewcontroller;8    9     //2. The controller that obtains modal final display, is the final UiviewcontrollerTenGreenviewcontroller *greencontroller = (Greenviewcontroller *) Nvcontroller.topviewcontroller; One     A     //3. Transferring Data -Greencontroller.name =@"I'm just a modal window"; -}
B. Reverse: Use agent "green" controller to transmit data to "red" controller

[iOS base Control-6.12.2] Modal

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.