Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243
One:
Two: Attention
For methods [Uipopovercontroller Dealloc] reached while popover is still visible.
When the popover is still showing, it hangs.
Don't allow popover to hang up when it's displayed.
PopOver must be dead when it's gone.
Three: Core code
- (ibaction) Popmenu: (ID) Item {//0. ContentMenuviewcontroller *menu = [[Menuviewcontroller alloc] init];//1. Create a uipopover Uipopovercontroller*popover = [[UipopovercontrollerAlloc] initwithcontentviewcontroller:[[UinavigationcontrollerAlloc] Initwithrootviewcontroller:menu];//2. Setting Dimensions//Popover.popovercontentsize = Cgsizemake (5); //3. From where to show-point to item[PopOver presentpopoverfrombarbuttonitem:item Permittedarrowdirections:uipopoverarrowdirectionany Animated:YES]; Self. PopOver= PopOver;}
Four: All code show Viewcontroller
#import "ViewController.h" #import "MenuViewController.h" @interface viewcontroller ()- (ibaction) Popmenu: (ID) Item;@property(nonatomic,Strong)Uipopovercontroller*popover;@end @implementation viewcontroller - (void) Viewdidload {[SuperViewdidload];}//-[uipopovercontroller Dealloc] reached while popover is still visible.//When the popover is still showing, it 's dead.//Do not allow PopOver to hang when displayed//PopOver must be dead when it disappears./** * Popup popover Menu * *- (ibaction) Popmenu: (ID) Item {//0. ContentMenuviewcontroller *menu = [[Menuviewcontroller alloc] init];//1. Create a uipopover Uipopovercontroller*popover = [[UipopovercontrollerAlloc] initwithcontentviewcontroller:[[UinavigationcontrollerAlloc] Initwithrootviewcontroller:menu];//2. Setting Dimensions//Popover.popovercontentsize = Cgsizemake (5); //3. From where to show-point to item[PopOver presentpopoverfrombarbuttonitem:item Permittedarrowdirections:uipopoverarrowdirectionany Animated:YES]; Self. PopOver= PopOver;}@end
Menuviewcontroller
#import "MenuViewController.h" @interface menuviewcontroller ()@property(nonatomic,Strong)Nsarray*titles;@end @implementation menuviewcontroller - (void) Viewdidload {[SuperViewdidload]; Self. Titles= @[@"Settings", @"Clear Cache", @"Exit", @"Basic Information"]; Self. Title= @"Menu"; Self. View. BackgroundColor= [UicolorBluecolor];CGFloatW = the;CGFloath = Self. Titles. Count* -; Self. Preferredcontentsize= Cgsizemake (W, h);//Self.contentsizeforviewinpopover = Cgsizemake (W, h);}#pragma mark-table view data source- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) Section {return Self. Titles. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static NSString*id = @"Cell";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:id];if(!cell) {cell = [[UITableViewCellAlloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; } cell. Textlabel. Text= Self. Titles[Indexpath. Row];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{Uiviewcontroller*VC = [[UiviewcontrollerALLOC] init]; Vc. View. BackgroundColor= [UicolorRedcolor]; [ Self. NavigationcontrollerPUSHVIEWCONTROLLER:VC Animated:YES];}@end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The basic use of popover for the ipad development of the Cat learning iOS