ios - 如何创建下拉弹出 View

标签 ios swift xcode uipopovercontroller

我想在点击按钮时显示一个下拉菜单。我点击下面的链接。

https://richardallen.me/2014/11/28/popovers.html

但我的按钮在表格 View 单元格中,我想在按钮下方显示弹出窗口。我搜索了很多并通过使用弹出窗口找到了方法。但我不知道如何使用和显示它。如果我点击上面的链接,则会显示以下错误。弹出窗口会全屏显示。所以请帮助我。

/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'>>

提前致谢。

最佳答案

使用 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()

希望对你有帮助

关于ios - 如何创建下拉弹出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647367/

相关文章:

ios - 除了内存泄漏,什么会随着时间的推移减慢 iOS 应用程序的速度?

ios - 将后退按钮添加到导航栏不起作用

ios - 如何强制 TextField 在横向模式下完全水平拉伸(stretch)

ios - 快速查看卡在纵向中的 View

ios - 如何创建一个重定向到我在 App Store 上的游戏的链接?

ios - 如何计算得分速度?

iphone - iOS 项目设置 : several apps slightly different between them. 几个目标

xcode - cocoa 教程建议

ios - NSStringCompareOptions 与 NSDiacriticInsensitiveSearch;

xcode - 更改 IBAction 上的按钮边框属性