【发布时间】:2016-04-25 01:26:05
【问题描述】:
我知道这是老派问题 - 但我确实搜索了网络并找到了要弃用的解决方案。我如何在 barButton 中将 UIAlertcontroller 实现为 popOver(箭头向上)。代码如下:
- (IBAction)eventSortingAction:(UIBarButtonItem *)sender {
UIAlertController * view= [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Select you Choice"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
//Do some thing here
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
[view dismissViewControllerAnimated:YES completion:nil];
}];
[view addAction:ok];
[view addAction:cancel];
[view setModalPresentationStyle:UIModalPresentationPopover];
view.modalInPopover = YES;
view.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
view.popoverPresentationController.delegate = self;
[self presentViewController:view animated:YES completion:nil];
UIView* senderView = [sender valueForKey:@"view"]; //HACK
UIPopoverPresentationController* popover = view.popoverPresentationController;
if (popover) {
popover.sourceView = senderView;
popover.sourceRect = senderView.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
popover.barButtonItem = self.actionBarButton;
popover.delegate = self;
}}
显然我总是得到一个“popover = nil”。请帮忙!提前致谢!
顺便说一下,这段代码不是我的,只是在 Xcode 中测试。
【问题讨论】:
-
使用实际创建
UIAlertController的代码更新您的问题。并解释您发布的代码实际发生的情况与您希望它执行的操作。 -
嗨,rmaddy,我在下面发布了更新的问题。我无法编辑我的问题 - 仍然缺乏声誉。
-
当然可以编辑。单击您的问题下的编辑链接。不要发布答案。
-
谢谢没看到,那里更新了。所以我真正想要的是有一个警报消息,它用我拥有的 uibarbutton 锚定(有一个指向 uibarbutton 的箭头)。实际上发生的是它显示了传统的警报控件
标签: ios uibarbuttonitem uipopovercontroller uialertcontroller