IPad control Uipopoverpresentationcontroller available with iphone

Source: Internet
Author: User

Uipopovercontroller was abandoned after iOS9, and,
IOS8 new control Uipopoverpresentationcontroller can be used on iphone and ipad, using basic same Uipopovercontroller
    • -(void) Ipadandiphonepopover {
      Menuviewcontroller *MENUVC = [[Menuviewcontroller alloc] init];
      Menuvc.modalpresentationstyle = Uimodalpresentationpopover;
      MenuVC.popoverPresentationController.sourceView = Self.view;
      MenuVC.popoverPresentationController.sourceRect = Self.testButton.frame;
      MenuVC.popoverPresentationController.permittedArrowDirections = Uipopoverarrowdirectionup;
      [Self PRESENTVIEWCONTROLLER:MENUVC animated:yes completion:nil];
      }
Code2:*-(Ibaction) PopOver: (ID) Sender {Addressviewcontroller*CONTENTVC =[[Addressviewcontroller alloc] init]; Contentvc.modalpresentationstyle=Uimodalpresentationpopover; ContentVC.popoverPresentationController.sourceView=Self.view; ContentVC.popoverPresentationController.sourceRect= CGRectMake ( -, -, -, -); ContentVC.popoverPresentationController.permittedArrowDirections=Uipopoverarrowdirectionup; [Self PRESENTVIEWCONTROLLER:CONTENTVC animated:yes completion:nil];}*ADDRESSVIEWCONTROLLER.M*#import "AddressViewController.h"@interfaceAddressviewcontroller () <uitableviewdelegate, uitableviewdatasource>@property (Weak, nonatomic) Iboutlet UITableView*mastertableview;//Province TableView@property (Weak, nonatomic) Iboutlet UITableView *detailtableview;//area TableView@property (nonatomic, strong) Nsarray*masterdatasource;//Province Data Source@property (nonatomic, strong) Nsarray *detaildatasource;//Regional data Sources@property (nonatomic, assign)intMasterindex;//Selected Provinces@end@implementationAddressviewcontroller- (void) viewdidload {[Super viewdidload]; _masterindex=0; Self.preferredcontentsize= Cgsizemake ( Max, -);}-(Nsarray *) Masterdatasource {if(_masterdatasource = =Nil) {_masterdatasource= @[@"Henan",@"Hebei",@"Jiangsu",@"Zhejiang",@"Guangdong"]; }    return_masterdatasource;}-(Nsarray *) Detaildatasource {if(_detaildatasource = =Nil) {_detaildatasource= @[@[@"Zhengzhou",@"Luoyang",@"Zhoukou",@"Kaifeng"],                              @[@"Shijiazhuang",@"Shijiazhuang 2"],                              @[@"Nanjing",@"Suzhou",@"Huaian",@"Huaibei",@"Jurong"],                              @[@"Hangzhou",@"Wenzhou",@"Taizhou",@"Ningbo",@"Ruian",@"Cangnan"],                              @[@"Guangzhou",@"Shenzhen"]                              ]; }    return_detaildatasource;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {if(TableView = =Self.mastertableview) {returnSelf.masterDataSource.count; }    if(TableView = =Self.detailtableview) {return[Self.detaildatasource[_masterindex] count]; }    return 0;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {if(TableView = =self.mastertableview) {UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:@"Master"]; if(Cell = =Nil) {Cell= [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:@"Master"]; } Cell.textLabel.text=Self.masterdatasource[indexpath.row]; returncell; } UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:@"Detail"]; if(Cell = =Nil) {Cell= [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:@"Detail"]; } Cell.textLabel.text=Self.detaildatasource[_masterindex][indexpath.row]; returncell;}- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {if(TableView = =_mastertableview) {_masterindex= (int) Indexpath.row; Self.preferredcontentsize= Cgsizemake ( -, -);    [_detailtableview Reloaddata]; }        if(TableView = =_detailtableview) {Self.preferredcontentsize= Cgsizemake ( Max, -);    [_detailtableview Reloaddata]; }}@end

  

    

Note: If you want to remove the arrow permittedarrowdirections = 0; and to set theSourceview, sourcerect It won't take effect until then.

IPad control Uipopoverpresentationcontroller available with iphone

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.