iPad 控制項 UIPopoverPresentationController 使用 iPhone可用

來源:互聯網
上載者:User

標籤:animate   省份   河北   ctr   button   ima   selectrow   dip   ati   

UIPopoverController 在iOS9之後被廢棄了,,,
iOS8 新控制項UIPopoverPresentationController可運用在iphone和iPad上,使用基本同 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(100, 100, 100, 100);    contentVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;    [self presentViewController:contentVC animated:YES completion:nil];}* AddressViewController.m* #import "AddressViewController.h"@interface AddressViewController () <UITableViewDelegate, UITableViewDataSource>@property (weak, nonatomic) IBOutlet UITableView *masterTableView; // 省份tableView@property (weak, nonatomic) IBOutlet UITableView *detailTableView; // 地區tableView@property (nonatomic, strong) NSArray *masterDataSource;           // 省份資料來源@property (nonatomic, strong) NSArray *detailDataSource;           // 地區資料來源@property (nonatomic, assign) int masterIndex;                     // 選中的省份@end@implementation AddressViewController- (void)viewDidLoad {    [super viewDidLoad];    _masterIndex = 0;    self.preferredContentSize = CGSizeMake(150, 300);}- (NSArray *)masterDataSource {    if (_masterDataSource == nil) {        _masterDataSource = @[@"河南", @"河北", @"江蘇", @"浙江", @"廣東"];    }    return _masterDataSource;}- (NSArray *)detailDataSource {    if (_detailDataSource == nil) {        _detailDataSource = @[@[@"鄭州", @"洛陽", @"周口", @"開封"],                              @[@"石家莊", @"石家莊2"],                              @[@"南京", @"蘇州", @"淮安", @"淮北", @"句容"],                              @[@"杭州", @"溫州", @"台州", @"寧波", @"瑞安", @"蒼南"],                              @[@"廣州", @"深圳"]                              ];    }    return _detailDataSource;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    if (tableView == self.masterTableView) {        return self.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];        return cell;    }        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detail"];    if (cell == nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detail"];    }    cell.textLabel.text = self.detailDataSource[_masterIndex][indexPath.row];    return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    if (tableView == _masterTableView) {        _masterIndex = (int)indexPath.row;        self.preferredContentSize = CGSizeMake(300, 300);        [_detailTableView reloadData];    }        if (tableView == _detailTableView) {        self.preferredContentSize = CGSizeMake(150, 300);        [_detailTableView reloadData];    }}@end

  

    

 注意:如果要去掉箭頭 permittedArrowDirections = 0;  並且要在設定了 sourceView, sourceRect 之後才會生效   

iPad 控制項 UIPopoverPresentationController 使用 iPhone可用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.