2016-03-08 286 views
0

我在使用UIPopoverController時收到警告,在閱讀蘋果文檔後,我明白這是過時的,我們必須使用UIPopoverPresentationController。請有人幫我替換下面的代碼。UIPopoverController已棄用

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

在另一種方法

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

我需要更換這些代碼,但找不到任何等價的。任何幫助讚賞。提前致謝 。

+0

谷歌「UIPopoverPresentationController示例」,你會看到大量的教程。 –

+0

使用UIPopoverPresentationController:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/ –

回答

3

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

1

下面代碼來顯示UIModalPresentationPopover上選自的UITableViewCell抽頭菜單按鈕;

-(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)); 
}