How to Create a uisplitviewcontroller application on iPad

Source: Internet
Author: User

Original article: Use of uisplitviewcontroller.

 


Use of uisplitviewcontroller on iPad

The screen size of the iPad is larger than that of the iPhone. Therefore, the iPad has a uisplitviewcontroller more than that of the iPhone on the interface, which is used to display the required interface in two columns when the iPad is on a horizontal screen, you can view the specific content on one side of the directory. The following describes how to use uisplitviewcontroller on iPad.

First, create a project: iPad. demo.

Then create a detailviewcontroller and rootviewcontroller, where rootviewcontroller inherits uitableviewcontroller. The colleague creates two corresponding XIB files. Delete ipad_demoviewcontroller. The corresponding classes are listed as follows:

 

Then modify ipad_demoappdelegate:

. H file:

# Import <uikit/uikit. h>
# Import "rootviewcontroller. H"
# Import "detailviewcontroller. H"
@ Class ipad_demoviewcontroller;

@ interface ipad_demoappdelegate: nsobject {< br> uiwindow * window;
uisplitviewcontroller * splitviewcontroller;
rootviewcontroller * rootviewcontroller;
detailviewcontroller * detailviewcontroller;
}

@ Property (nonatomic, retain) iboutlet uiwindow * window;
@ Property (nonatomic, retain) iboutlet uisplitviewcontroller * splitviewcontroller;
@ Property (nonatomic, retain) iboutlet rootviewcontroller * rootviewcontroller;
@ Property (nonatomic, retain) iboutlet detailviewcontroller * detailviewcontroller;
@ End

. M file:

-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {
// Override point for customization after app launch.
 [Window addsubview: splitviewcontroller. View];
[Window makekeyandvisible];

Return yes;
}

Modify the mainwindow. XIB file:

Add a uisplitviewcontroller container:

Controls in IB are associated with corresponding events: During the connection process, press and hold the control key, click ipad_demo app delegate, connect to the split view controller, and select Custom events, the final result is as follows:

Finally, replace the corresponding container with a custom container: the implementation method is

The final result is:

Now we are implementing detailviewcontroller:

    1. First, modify the corresponding file:

. modify the H file as follows:

#import
@ interface detailviewcontroller: uiviewcontroller {
iboutlet uilabel * lable;
iboutlet uiswitch * swititch;
nsindexpath * index;
}< br> -(void) deetail :( ID) sender;
@ property (nonatomic, retain) uilabel * lable;
@ property (nonatomic, retain) uiswitch * swititch;
@ end

Modify the. M file as follows:

# Import "detailviewcontroller. H"
@ Implementation detailviewcontroller
@ Synthesize lable, switle;
-(Void) viewdidload {
[Super viewdidload];
}
-(Void) viewwillappear :( bool) animated
{

}
-(Void) deetail :( ID) sender
{
Index = sender;
Self. lable. Text = [nsstring stringwithformat: @ "row % d, section % d", [index row], [index section];
If ([index row] % 2 = 0 ){
Self. switch1.on = yes;
} Else {
Self. switch1.on = no;
}
}
-(Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {
Return yes;
}
-(Void) didreceivememorywarning {
[Super didreceivememorywarning];
}
-(Void) viewdidunload {
[Super viewdidunload];
Self. lable = nil;
Self. switcounter = nil;
}
-(Void) dealloc {
[Self. lable release];
[Self. switch1 release];
[Super dealloc];
}
@ End

2. Modify the XIB file:

Add the corresponding controls, and the corresponding components are associated with the corresponding events.

Finally, we implement rootviewcontroller:

    1. First, modify the corresponding file:

The. h file is as follows:

# Import <uikit/uikit. h>
@ Class detailviewcontroller;
@ Interface rootviewcontroller: uitableviewcontroller {

Iboutlet detailviewcontroller * detailviewcontroller;
}
@ Property (nonatomic, retain) detailviewcontroller * detailviewcontroller;
@ End

The. M file is as follows:

-(Nsinteger) numberofsectionsintableview :( uitableview *) tableview {
// Return the number of sections.
Return 2;
}

-(Nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {
// Return the number of rows in the Section.
Return 7;
}

 

-(Uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {
Static nsstring * cellidentifier = @ "cell ";
Uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier: cellidentifier];
If (cell = nil ){
Cell = [[[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault reuseidentifier: cellidentifier] autorelease];
}
// Configure the cell...
Cell. textlabel. Text = [nsstring stringwithformat: @ "row % d Section % d", [indexpath row], [indexpath section];
Return cell;
}

 

-(Void) tableview :( uitableview *) tableview didselectrowatindexpath :( nsindexpath *) indexpath {
// Navigation logic may go here. Create and push another view controller.
// Detailviewcontroller * detailviewcontroller = [[detailviewcontroller alloc] initwithnibname: @ "detailviewcontroller" Bundle: Nil];
// [Self. navigationcontroller pushviewcontroller: detailviewcontroller animated: Yes];
// [Detailviewcontroller release];
[Detailviewcontroller deetail: indexpath];
}

2. Modify the XIB file:

Related events are associated with controls.

The running result is as follows:

 

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.