- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何显示 UIActionsheet
在 iPad 中,当我使用我当前的代码时,它给了我这个错误:
Your application has presented a
UIAlertController
(<UIAlertController: 0x7f9ec624af70>
) of styleUIAlertControllerStyleActionSheet
. ThemodalPresentationStyle
of aUIAlertController
with this style isUIModalPresentationPopover
. You must provide location information for this popover through the alert controller'spopoverPresentationController
. You must provide either asourceView
andsourceRect
or abarButtonItem
. If this information is not known when you present the alert controller, you may provide it in theUIPopoverPresentationControllerDelegate
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, message: nil, preferredStyle: .ActionSheet)
optionMenu.popoverPresentationController?.sourceView = self.view
optionMenu.popoverPresentationController?.sourceRect = self.view.bounds
但它对我不起作用,可能是因为我的 ActionSheet 的发件人在 UItableviewCell 上。
我厌倦了将 AlertController 的 Sourceview 设置为 tableView 的 Cell,但它没有正确放置,有时它部分可见这是我尝试过的:
optionMenu.popoverPresentationController?.sourceView = currentCell.contentView
optionMenu.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("", comment: ""), preferredStyle: .ActionSheet)
cameraSettingsAlert.modalPresentationStyle = .Popover
let photoResolutionAction = UIAlertAction(title: NSLocalizedString("Photo Resolution", comment: ""), style: .Default) { action in
}
let cameraOrientationAction = UIAlertAction(title: NSLocalizedString("Camera Orientation", comment: ""), style: .Default) { action in
}
let flashModeAction = UIAlertAction(title: NSLocalizedString("Flash Mode", comment: ""), style: .Default) { action in
}
let timeStampOnPhotoAction = UIAlertAction(title: NSLocalizedString("Time Stamp on Photo", comment: ""), style: .Default) { action in
}
let cancel = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), 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, animated: true, completion: nil)
关于ios - 如何在 iPad 中显示 Actionsheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38858878/
我是一名优秀的程序员,十分优秀!