就像标题所说,我正在使用Swift 3.0处理Xcode项目。我希望在当前视图中按下按钮,以弹出方式显示较小的视图。 此弹出窗口将是一个表视图,它将显示一个标签+一个文本框,以便在特定数组中有多个单元格。大小将限制在屏幕的一部分,表格视图自然可以滚动。
我理解如何以编程方式创建视图,我得到了" hidden = true"概念。我真正挣扎的是获取表格视图。从理论上讲,我可以在我的故事板中设计视图,但是有没有办法按名称引用它并将超级强加于当前视图?
感谢您的帮助!
编辑:
感谢我的帮助,我得到了这段代码:
@IBOutlet weak var CreatePost: UIButton!
@IBAction func CreatePost(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let popVC = storyboard.instantiateViewController(withIdentifier: "CreateAccountPop") // your viewcontroller's id
popVC.preferredContentSize = CGSize(width: 500, height: 600)
popVC.modalPresentationStyle = .popover
let popover = popVC.popoverPresentationController
popover?.delegate = self as? UIPopoverPresentationControllerDelegate
//sourceRect and sourceView is required in case of iPad
popover?.sourceRect = (sender as AnyObject).frame //give anchor frame
popover?.sourceView = sender as! UIView //give anchor view
self.present(popVC, animated: true, completion: nil)
}
代码显示视图控制器,但占用整个屏幕。我似乎无法弄清楚如何限制其大小
答案 0 :(得分:1)
设计ViewController(最好在故事板中),使视图不透明。添加具有您选择大小的tableview。
你可以像这样展示popover
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let popVC = storyboard.instantiateViewController(withIdentifier: "PopVC") // your viewcontroller's id
popVC.modalPresentationStyle = .popover
let popover = popVC.popoverPresentationController
popover?.delegate = self
//sourceRect and sourceView is required in case of iPad
popover?.sourceRect = sender.frame //give anchor frame
popover?.sourceView = sender //give anchor view
self.present(popVC, animated: true, completion: nil)
并且不要忘记将您的呈现视图控制器符合UIPopoverPresentationControllerDelegate