ios – 如何在iPad中显示动作表

ios – 如何在iPad中显示动作表,第1张

概述当我使用当前代码时,如何在iPad中显示UIActionsheet,它给我这个错误: Your application has presented a UIAlertController (<UIAlertController: 0x7f9ec624af70>) of style UIAlertControllerStyleActionSheet. The modalPresentationSty 当我使用当前代码时,如何在iPad中显示UIActionsheet,它给我这个错误:

Your application has presented a UIAlertController (<UIAlertController: 0x7f9ec624af70>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provIDe location information for this popover through the alert controller’s popoverPresentationController. You must provIDe either a sourceVIEw and sourceRect or a barbuttonItem. If this information is not kNown when you present the alert controller,you may provIDe it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.

这在iPhone上工作得很好:

let optionMenu = UIAlertController(Title: nil,message: nil,preferredStyle: .ActionSheet)let reminderAction = UIAlertAction(Title: "Reminder",style: .Default,handler: {                (alert: UIAlertAction!) -> VoID in }optionMenu.addAction(reminderAction)self.presentVIEwController(optionMenu,animated: true,completion: nil)

我遇到了一些类似的问题,解决方法是:

let optionMenu = UIAlertController(Title: nil,preferredStyle: .ActionSheet)optionMenu.popoverPresentationController?.sourceVIEw = self.vIEwoptionMenu.popoverPresentationController?.sourceRect = self.vIEw.bounds

但它并没有对我有用,可能是因为我的ActionSheet的发件人在UItablevIEwCell上.

我厌倦了将AlertController的SourcevIEw设置为tableVIEw的Cell,但它没有正确放置,有时它部分可见这是我试过的:

optionMenu.popoverPresentationController?.sourceVIEw = currentCell.contentVIEwoptionMenu.popoverPresentationController?.sourceRect = currentCell.contentVIEw.bounds

任何线索如何解决这个问题?

解决方法 下面给出的示例代码适用于iPhone和iPad.

guard let vIEwRect = sender as? UIVIEw else {            return        }    let cameraSettingsAlert = UIAlertController(Title: NSLocalizedString("Please choose a course",comment: ""),message: NSLocalizedString("",preferredStyle: .ActionSheet)    cameraSettingsAlert.modalPresentationStyle = .Popover    let photoResolutionAction = UIAlertAction(Title: NSLocalizedString("Photo Resolution",style: .Default) { action in    }    let cameraOrIEntationAction = UIAlertAction(Title: NSLocalizedString("Camera OrIEntation",style: .Default) { action in    }    let flashModeAction = UIAlertAction(Title: NSLocalizedString("Flash Mode",style: .Default) { action in    }    let timeStampOnPhotoAction = UIAlertAction(Title: NSLocalizedString("Time Stamp on Photo",style: .Default) { action in    }    let cancel = UIAlertAction(Title: NSLocalizedString("Cancel",style: .Cancel) { action in    }    cameraSettingsAlert.addAction(cancel)    cameraSettingsAlert.addAction(cameraOrIEntationAction)    cameraSettingsAlert.addAction(flashModeAction)    cameraSettingsAlert.addAction(timeStampOnPhotoAction)    cameraSettingsAlert.addAction(photoResolutionAction)    if let presenter = cameraSettingsAlert.popoverPresentationController {        presenter.sourceVIEw = vIEwRect;        presenter.sourceRect = vIEwRect.bounds;    }    presentVIEwController(cameraSettingsAlert,completion: nil)
总结

以上是内存溢出为你收集整理的ios – 如何在iPad中显示动作表全部内容,希望文章能够帮你解决ios – 如何在iPad中显示动作表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1082738.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存