UIPopoverController已弃用
问题描述:
我在使用UIPopoverController
时收到警告,在阅读苹果文档后,我明白这是过时的,我们必须使用UIPopoverPresentationController
。请有人帮我替换下面的代码。UIPopoverController已弃用
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];
或者您可以使用下面的链接。
答
下面代码来显示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));
}
谷歌“UIPopoverPresentationController示例”,你会看到大量的教程。 –
使用UIPopoverPresentationController:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/ –