我想在点击按钮时显示一个下拉菜单。我按照以下链接进行操作。
https://richardallen.me/2014/11/28/popovers.html
但是我的按钮位于表格视图单元格中,我想在按钮下方显示弹出窗口。我搜索了很多并通过使用弹出窗口找到了方法。但我不知道如何使用和显示它。如果我按照上面的链接然后显示下面的错误。弹出窗口全屏显示。所以请帮助我。
/Base.lproj/Main.storyboard:%20Couldn't%20compile%20connection:%20<IBCocoaTouchOutletConnection:%200x7fc9f5fa6330%20(KPd-LK-kJS)%20source=<IBProxyObject:%200x7fc9f5fa6020%20(mgH-pb-OhC)%20'Placeholder%20for%20UIStoryboardPopoverPresentationSegueTemplate%20with%20OID%20qoG-n8-Yu0'>%20property=anchorView%20destination=<IBUIButton:%200x7fc9f796dd40%20(xk1-Vu-vnj)%20'Anchor%20View'>>
先谢谢。
答案 0 :(得分:2)
使用tableview和popover创建一个下拉列表有点耗时,但幸运的是我们有一个替代解决方案,使用这个library非常容易使用
<强>初始化:强>
let dropDown = DropDown()
// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem
// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Car", "Motorcycle", "Truck"]
处理选择:
// Action triggered on selection
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
print("Selected item: \(item) at index: \(index)")
}
// Will set a custom width instead of the anchor view width
dropDownLeft.width = 200
显示操作:
dropDown.show()
dropDown.hide()
希望这会对你有所帮助