我有一个工具栏,其UIBarButtomItem
左上角有一个标签为Admin的工具栏。
我需要在点击弹出窗口时显示它,但它显示在错误的位置,并出现在屏幕的左上方:
这是打开弹出窗口的功能:
// this IBAction is assigned only to the Admin bar button item
@IBAction func openAdmin(sender: UIBarButtonItem) {
let alertController = UIAlertController(title: nil, message: "Elige una opción", preferredStyle: .ActionSheet)
// action button initializations... ... ...
let barButtonItemSize = sender.valueForKey("view")
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame
presentViewController(alertController, animated: true, completion: nil)
}
当我触摸管理栏按钮时,也会在控制台上收到此警告:
对尚未渲染的视图进行快照会导致快照为空。确保在快照之前或屏幕更新之后至少快照已渲染过一次视图
我究竟做错了什么?或我需要怎么做才能将弹出窗口显示在管理员顶部?
代替
alertController.popoverPresentationController?.sourceView = self.view
alertController.popoverPresentationController?.sourceRect = barButtonItemSize!.frame
和
alertController.popoverPresentationController?.sourceView = sender
alertController.popoverPresentationController?.barButtonItem = sender
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句