Cat learns iOS ipad Development popover Palette App _popover show other controls can still interact

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243

One: Effect

Behind is the Xcode console.

Two: Code Viewcontroller
#import "ViewController.h" #import "ColorsViewController.h"  @interface viewcontroller () <colorsviewcontrollerdelegate,  Uipopovercontrollerdelegate>- (ibaction) ButtonClick: (UIButton*) btn;@property(nonatomic,Weak)UIButton*colorbutton;@property(nonatomic,Strong)Uipopovercontroller*popover;@property(Weak,nonatomic)Iboutlet UIButton*greenbutton;-(ibaction) Greenbuttonclick;@end @implementation viewcontroller - (void) Viewdidload {[SuperViewdidload];} - (ibaction) Greenbuttonclick {NSLog(@"Greenbuttonclick");} - (ibaction) ButtonClick: (UIButton*) BTN {//0. ContentColorsviewcontroller *colors = [[Colorsviewcontroller alloc] init]; Colors. Delegate= Self;//1. Create     Self. PopOver= [[UipopovercontrollerAlloc] initwithcontentviewcontroller:colors]; Self. PopOver. Delegate= Self;//2. Display//[Self.popover Presentpopoverfromrect:cgrectmake (InView:btn.superview) Permittedarrowdirections:uipopoverarrowdirectionany Animated:yes];[ Self. PopOverPresentpopoverfromrect:cgrectmake (924,668, -, -) inview:btn. SuperviewPermittedarrowdirections:uipopoverarrowdirectionany Animated:YES];//[Self.popover presentPopoverFromRect:btn.bounds inview:btn permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];//[Self.popover presentPopoverFromRect:btn.frame inView:btn.superview permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];    //3. Set where controls can still interact with the user when the PopOver is displayed     Self. PopOver. Passthroughviews= @[ Self. Greenbutton]; Self. Colorbutton= BTN;}#pragma mark-color selector agent- (void) Colorsviewcontroller: (Colorsviewcontroller *) VC Didselectcolor: (Uicolor*) color{ Self. Colorbutton. BackgroundColor= color;//Close PopOver[ Self. PopOverDismisspopoveranimated:YES];}#pragma agent for Mark-popover- (void) Popovercontrollerdiddismisspopover: (Uipopovercontroller*) popovercontroller{NSLog(@"PopOver destroyed.");}@end
Colorsviewcontroller
#import <UIKit/UIKit.h>  @class colorsviewcontroller; @protocol colorsviewcontrollerdelegate <nsobject>@optional- (void) Colorsviewcontroller: (Colorsviewcontroller *) VC Didselectcolor: (Uicolor*) color;@end @interface colorsviewcontroller : uitableviewcontroller @property(nonatomic,Weak)ID<ColorsViewControllerDelegate> delegate;@end
#import "ColorsViewController.h"  @interface colorsviewcontroller ()@end @implementation colorsviewcontroller - (void) Viewdidload {[SuperViewdidload]; Self. TableView. Separatorstyle= Uitableviewcellseparatorstylenone;} - (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}#pragma mark-table view data source- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) Section {return  -;} - (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. Selectionstyle= Uitableviewcellselectionstylenone; } cell. BackgroundColor= [UicolorColorwithred:arc4random_uniform (255)/255.0Green:arc4random_uniform (255)/255.0Blue:arc4random_uniform (255)/255.0Alpha1.0];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{if([ Self. DelegateRespondstoselector:@selector(Colorsviewcontroller:didselectcolor:)]) {Uicolor*color = [TableView Cellforrowatindexpath:indexpath]. BackgroundColor; [ Self. DelegateColorsviewcontroller: SelfDidselectcolor:color]; }}@end

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Cat learns iOS ipad Development popover Palette App _popover show other controls can still interact

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.