PopoverPresentationController以零开头
创建了一个SingleViewApplication,我已经放置了一个按钮。
现在点击按钮我需要将tableView显示为popover。 TableViewController是在xib中创建的。
问题是tableViewController.popoverPresentationController始终为零,参见下面的代码
let filterVC = TableViewController(nibName: "TableViewController", bundle: nil) var filterDistanceViewController = UINavigationController(rootViewController: filterVC) filterDistanceViewController.preferredContentSize = CGSize(width: 300, height: 200) let popoverPresentationViewController = filterDistanceViewController.popoverPresentationController popoverPresentationViewController?.permittedArrowDirections = .any if let pop = filterDistanceViewController.popoverPresentationController { pop.delegate = self }
在上面的代码filterDistanceViewController.popoverPresentationController总是为零
任何正确方向的提示都将受到高度赞赏。
您没有呈现任何内容,因此您需要在当前viewcontroller上显示popoverPresentationViewController
,例如:
@IBAction func importantButtonPressed(_ sender: UIButton) { let tableViewController = UITableViewController() tableViewController.modalPresentationStyle = .popover present(tableViewController, animated: true, completion: nil) if let pop = tableViewController.popoverPresentationController { pop.delegate = self } }
你可以在下面做。
@IBAction func popoverBtnPressed(_ sender: Any) { let vc2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController2") vc2.modalPresentationStyle = .popover vc2.popoverPresentationController?.delegate = self vc2.popoverPresentationController?.barButtonItem = popoverBtn vc2.popoverPresentationController?.sourceRect = .zero present(vc2, animated: true, completion: nil) }
在VC上设置modalPresentationStyle
之前, popoverPresentationController
属性将为nil
。 确保在访问之前设置modalPresentationStyle
。
- GCDAsyncSocket服务器仅在第一次接收数据
- 如何从string中提取表情符号?
- NSError * vs NSError **
- 外部延伸和内部的可调整的UIImage保持不变
- VS2013 Cordova iOS Remotebuild错误无法POST /build/tasks?command=build&vcordova=4.3.1&cfg=debug
- 我执行后如何恢复:git reset –hard HEAD
- 从iCloud文档选取器附加iWork文档不起作用,因为它们是目录而不是文件
- UISearchController使控制器变黑
- 如何清除/重置所有CoreData中的一对多关系