"iOS Dev-107" Uisplitviewcontroller: How to get Master and detail controller, the core is how to use the agent

Source: Internet
Author: User

Uisplitviewcontroller is also a unique class for the ipad. Create Uisplitviewcontroller in Storyboard way.

(1) directly from the code to create, first set the window's root controller in the Appdelegate

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Self.window=[[uiwindow Alloc]initwithframe:[uiscreen Mainscreen].bounds];    Wpmainsplitviewcontroller *splitvc=[[wpmainsplitviewcontroller Alloc]init];     SELF.WINDOW.ROOTVIEWCONTROLLER=SPLITVC;    [Self.window makekeyandvisible];    return YES;}

Then set the details in our protagonist Wpmainsplitviewcontroller (a class that inherits from Uisplitviewcontroller)

-(void) viewdidload {    [super viewdidload];    Set two navigation controller with TableView as left and right view    Lefttableviewcontroller *left=[[lefttableviewcontroller Alloc]init];    Uinavigationcontroller *leftnav=[[uinavigationcontroller Alloc]initwithrootviewcontroller:left];    Righttableviewcontroller *right=[[righttableviewcontroller Alloc]init];    Uinavigationcontroller *rightnav=[[uinavigationcontroller Alloc]initwithrootviewcontroller:right];    Self.viewcontrollers=[nsarray Arraywithobjects:leftnav,rightnav, nil];

In fact, it can be.


(2) commonly used is the agent. Separated view Controller has its own proxy,uisplitviewcontrollerdelegate

For example, in the above code, add:

-(void) viewdidload {    [super viewdidload];    ......    Self.delegate=right;    ......}

Then in right this table view controller can implement the proxy method (commonly used such as listening to the app when the master view of the hidden and display): Hidden when the upper-left corner of the detail view appears barbuttonitem used to click the master view appears, This barbuttonitem does not appear when it is displayed.

Show or hide is generally for the left side of the menu-based view-(void) Splitviewcontroller: (Uisplitviewcontroller *) svc Willshowviewcontroller: ( Uiviewcontroller *) Aviewcontroller Invalidatingbarbuttonitem: (Uibarbuttonitem *) barbuttonitem{    //button click event officially encapsulated    Self.navigationitem.leftbarbuttonitem=nil;} -(void) Splitviewcontroller: (Uisplitviewcontroller *) svc Willhideviewcontroller: (Uiviewcontroller *) Aviewcontroller Withbarbuttonitem: (Uibarbuttonitem *) Barbuttonitem Forpopovercontroller: (UIPopoverController *) pc{    [Email protected] "class";    Self.navigationitem.leftbarbuttonitem=barbuttonitem;}

(3) Of course, it should be more normal to click on the left side of the view of things, the right side will appear corresponding to the view. This is also with the agent. But this time the agent is the Detail view (right) is the master drive in (left) of the agent.

-(void) viewdidload {    [super viewdidload];    When you need to click on the left side and respond to the right, you can take advantage of the proxy (remove the left-and both sides of the controller and set the proxy)    Lefttableviewcontroller *leftone=[self.viewcontrollers Firstobject];    Righttableviewcontroller *rightone=[self.viewcontrollers Lastobject];    Leftone.delegate=rightone;}

Note: The general project does not write the master and detail view controllers directly in the Split view controller, so if you want to get the left and right 2 views, you need to use the above method, This is obtained from the self.viewcontrollers using Firstobject and Lastobject.

"iOS Dev-107" Uisplitviewcontroller: How to get Master and detail controller, the core is how to use the agent

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.