ipad Proprietary API: Floating view controller Uipopoverviewcontroller and Split view Controller Uisplitviewcontroller
----------------------------------Uipopoverviewcontroller----------------------------------
Appdelegate.m
Uinavigationcontroller *Navi; if ([[Uidevice currentdevice]userinterfaceidiom]==Uiuserinterfaceidiompad) {//ipad device new]]; } Else { new]]; } = Navi;
Ipadviewcontroller.m
#import "IpadViewController.h"#import "ListViewController.h"@interfaceIpadviewcontroller () {Uipopovercontroller*_leftpopcontroller;}@end@implementationIpadviewcontroller- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view.Self.title =@"Ipad"; Self.navigationItem.rightBarButtonItem= [[Uibarbuttonitem alloc]initwithtitle:@"Pop"Style:uibarbuttonitemstyledone target:self Action: @selector (Jumpleftpop:)];}-(void) Jumpleftpop: (ID) sender{if(_leftpopcontroller = =Nil) {Listviewcontroller*list = [ListviewcontrollerNew]; Uinavigationcontroller*nav =[[Uinavigationcontroller alloc]initwithrootviewcontroller:list]; Floating View Controller _leftpopcontroller=[[Uipopovercontroller Alloc]initwithcontentviewcontroller:nav]; _leftpopcontroller.Delegate=Self ; _leftpopcontroller.popovercontentsize= Cgsizemake ( the, -); List.pop=_leftpopcontroller; } [_leftpopcontroller Presentpopoverfrombarbuttonitem:sender permittedarrowdirections:uipopoverarrowdirectionup animated:yes];//modal Display}
Listviewcontroller.m
#import "ListViewController.h"@interfaceListviewcontroller ()@end@implementationListviewcontroller- (void) viewdidload{Self.title=@"Choose the color you like"; _listtableview=[[UITableView alloc]initwithframe:self.view.frame Style:uitableviewstyleplain]; _listtableview.Delegate=Self ; _listtableview.datasource=Self ; [Self.view Addsubview:_listtableview]; [Super Viewdidload]; //Do any additional setup after loading the view.Self.datasourse= [[Nsmutablearray alloc]initwitharray: @[@"Red",@"Yellow",@"Blue",@"Green",@"Gray"]]; }-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{returnSelf.dataSourse.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *identifier =@"Cellidentifier"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:identifier]; if(Cell = =Nil) {Cell=[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier]; } Cell.textLabel.text=[Self.datasourse ObjectAtIndex:indexPath.row]; Cell.selectionstyle=Uitableviewcellselectionstylenone; returncell;}-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{[Self.pop dismisspopoveranimated:yes];}
-----------------------------------------Sliptviewcontrollerdemo-----------------------------------------
Appdelegate.m
Masterviewcontroller *master =[[Masterviewcontroller alloc]init]; Uinavigationcontroller*navmaster =[[Uinavigationcontroller Alloc]initwithrootviewcontroller:master]; Detailviewcontroller*detail =[[Detailviewcontroller alloc]init]; Uinavigationcontroller*navdetail =[[Uinavigationcontroller Alloc]initwithrootviewcontroller:detail]; //Split View ControllerUisplitviewcontroller *split =[[Uisplitviewcontroller alloc]init]; Split.viewcontrollers=@[navmaster,navdetail]; Split.Delegate=detail; Split.tabbaritem=Detail.tabbaritem; Self.window.rootViewController= Split;
DetailViewController.h
@interface Detailviewcontroller:uiviewcontroller<uipopovercontrollerdelegate,uisplitviewcontrollerdelegate> *Pop; @end
Detailviewcontroller.m
#import "DetailViewController.h"#import "ModelViewController.h"@interfaceDetailviewcontroller () {Modelviewcontroller*_modelcontroller; Uisegmentedcontrol*_segment;}@end@implementationDetailviewcontroller- (void) viewdidload{[Super Viewdidload]; Self.title=@"Detail"; Self.view.backgroundColor=[Uicolor Whitecolor]; _segment= [[Uisegmentedcontrol alloc]initwithitems:@[@" One",@" Both",@"three",@" Four"]]; _segment.frame= CGRectMake ( -, -, the, +); _segment.selectedsegmentindex=0; [Self.view addsubview:_segment]; UIButton*NEXTBTN =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Nextbtn.frame= CGRectMake ( -, $, $, +); [Nextbtn settitle:@"Nextcontroller"Forstate:0]; [Nextbtn addtarget:self Action: @selector (Nextcontrller:) forControlEvents:7]; [Self.view ADDSUBVIEW:NEXTBTN]; }-(void) Nextcontrller: (ID) sender{if(_modelcontroller==Nil) {_modelcontroller=[[Modelviewcontroller alloc]init]; } _modelcontroller.modaltransitionstyle= Uimodaltransitionstylefliphorizontal;//turn out animation styles Switch(_segment.selectedsegmentindex) { Case 0: {_modelcontroller.modalpresentationstyle= Uimodalpresentationfullscreen;//full screen, default style, iphone only fullscreen Break; } Case 1: {_modelcontroller.modalpresentationstyle= Uimodalpresentationpagesheet;//Vertical screen full screen, horizontal screen width 768 Break; } Case 2: {_modelcontroller.modalpresentationstyle= Uimodalpresentationformsheet;//not full-screen, fixed 540*620 Break; } Case 3: {_modelcontroller.modalpresentationstyle= Uimodalpresentationcurrentcontext;//Detailcontroller controller itself display size, full screen self controller Break; } default: Break; } [Self Presentviewcontroller:_modelcontroller animated:yes completion:nil];}#pragmaMark Split View Controller delegatemethods-(void) Splitviewcontroller: (Uisplitviewcontroller *) Svc Willhideviewcontroller: (Uiviewcontroller*) Aviewcontroller Withbarbuttonitem: (Uibarbuttonitem*) Barbuttonitem Forpopovercontroller: (Uipopovercontroller*) pc{Barbuttonitem.title=@"Home List"; Self.navigationItem.leftBarButtonItem=Barbuttonitem; Self.pop=pc;}- (void) Splitviewcontroller: (uisplitviewcontroller*) Svc Willshowviewcontroller: (Uiviewcontroller*) Aviewcontroller Invalidatingbarbuttonitem: (Uibarbuttonitem*) barbuttonitem{Self.navigationItem.leftBarButtonItem=Nil; Self.pop=Nil;}@end
MasterViewController.h
@interface Masterviewcontroller:uiviewcontroller<uitableviewdatasource,uitableviewdelegate>** Listtableview; @end
Masterviewcontroller.m
#import "MasterViewController.h"@interfaceMasterviewcontroller ()@end@implementationMasterviewcontroller- (void) viewdidload{Self.title=@"Master"; _listtableview=[[UITableView alloc]initwithframe:self.view.frame Style:uitableviewstyleplain]; _listtableview.Delegate=Self ; _listtableview.datasource=Self ; [Self.view Addsubview:_listtableview]; [Super Viewdidload]; Self.datasourse= [[Nsmutablearray alloc]initwitharray: @[@"Red",@"Yellow",@"Blue",@"Green",@"Gray"]];}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{returnSelf.dataSourse.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *identifier =@"Cellidentifier"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:identifier]; if(Cell = =Nil) {Cell=[[UITableViewCell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier]; } Cell.textLabel.text=[Self.datasourse ObjectAtIndex:indexPath.row]; Cell.selectionstyle=Uitableviewcellselectionstylenone; returncell;}@end
Demo Download: Https://github.com/forrHuen/iPadDemo
ipad Development proprietary Api-uipopoverviewcontroller and Uisplitviewcontroller