簡體   English   中英

不推薦使用UIPopoverController

[英]UIPopoverController deprecated

我在使用UIPopoverController時收到警告,閱讀蘋果文檔后,我了解它已被棄用,我們必須使用UIPopoverPresentationController 請任何人幫助我替換下面的代碼。

UIPopoverController *popover = [[UIPopoverController alloc]   initWithContentViewController:viewDownloader];
[popover setPopoverContentSize: CGSizeMake(320, 450)];

在另一種方法

if (popover!=nil && popover.popoverVisible == YES)
    [popover dismissPopoverAnimated:YES];

我需要替換這些代碼,但找不到任何等效的代碼。 任何幫助表示贊賞。 提前致謝 。

UIModalPresentationPopover

UIModalPresentationPopover是更換UIPopoverController

在iOS 8.0和更高版本中可用。

ModalViewController *modal = [[ModalViewController alloc] init];
modal.modalPresentationStyle = UIModalPresentationPopover;
modal.transitioningDelegate = self;
modal.popoverPresentationController.sourceView = self.view;
modal.popoverPresentationController.sourceRect = CGRectZero;
modal.popoverPresentationController.delegate = self;

[self presentViewController:modal animated:YES completion:nil];

否則,您可以使用下面的鏈接。

UIPopoverPresentationController

下面的代碼顯示從選定的UITableViewCell輕按的菜單按鈕上的UIModalPresentationPopover

-(void)menuButtonTapped:(UIButton *)button {

    UITableViewCell *cell=(UITableViewCell *)[[button superview] superview];
    self.selectedIndexPath = [self.tableView indexPathForCell:cell];
    CGRect rectOfCellInTableView = [self.tableView rectForRowAtIndexPath: self.selectedIndexPath];
    CGRect rectOfCellInSuperview = [self.tableView convertRect: rectOfCellInTableView toView:_tableView.superview];
    rectOfCellInSuperview.origin.x = self.view.frame.size.width-50;

    MyMenuPopoverController *myMenuPopoverController= [[MyMenuPopoverController alloc] initWithStyle:UITableViewStylePlain];

    myMenuPopoverController.modalPresentationStyle = UIModalPresentationPopover;
    myMenuPopoverController.popoverPresentationController.sourceView = self.view;
    myMenuPopoverController.popoverPresentationController.sourceRect = rectOfCellInSuperview;
    myMenuPopoverController.preferredContentSize = CGSizeMake(250,(myMenuPopoverController.arrMenuOptions.count * 40));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM