测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | Apache 2 |
发布上次发布 | 2018年3月 |
SPM支持 SPM | ✗ |
由 Dan Loewenherz maintain.
TableViewPopoverPresenting 是一个简单、即插即用的协议,它为您的表格视图提供了在响应单元格点击时显示弹出视图控制器的能力。它仅对您定义的单元格覆盖了标准的表格视图点击处理器,其他所有内容都回退到您现有的 tableView(_:didSelectRowAt:)
实现中。
在美好往日,为了在您的表格视图单元格上显示弹出视图,您需要做几件事情
UITapGestureRecognizer
。UITableView
。UIViewController
符合 UIGestureRecognizerDelegate
。UITableView
的触摸处理器 tableView(_:didSelectRowAt:)
。这些都需要通过 StackOverflow 帖子进行细致检查,以确保您正在按照“正确”的方式进行。显然,这是很愚蠢的。您不应该需要为如此简单的事情做所有这些工作。这正是 TableViewPopoverPresenting 介入的地方。
TableViewPopoverPresenting 通过 CocoaPods 提供。要安装它,只需将下面的行添加到您的 Podfile 中
pod "TableViewPopoverPresenting"
通过将以下行添加到您的 Podfile 中,使用 Cocoapods 安装 TableViewPopoverPresenting。
pod "TableViewPopoverPresenting"
在包含表格视图控制器的文件中导入 TableViewPopoverPresenting
import TableViewPopoverPresenting
在 viewDidLoad
中调用 initializeTableViewPopover
func viewDidLoad() {
super.viewDidLoad()
# ...
initializeTableViewPopover()
# ...
}
实现 viewController(forPopoverAt:)
以在哪些索引路径显示哪个视图控制器。例如。
func viewController(forPopoverAt: IndexPath) -> UIViewController? {
if indexPath.row == 0 {
let actionSheet = UIAlertController(title: "Important Question", message: "What's your favorite color?", preferredStyle: .ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Red", style: .Default) { _ in })
actionSheet.addAction(UIAlertAction(title: "Green", style: .Default) { _ in })
actionSheet.addAction(UIAlertAction(title: "Blue", style: .Default) { _ in })
return actionSheet
} else {
return nil
}
}
好了……这样就完成了。当在任何部分的第一个行上检测到点击时,将出现一个 nice action sheet。简单,对吧?
无。
Dan Loewenherz,[email protected]
TableViewPopoverPresenting 在 Apache 2.0 许可证下提供。有关更多信息,请参阅 LICENSE 文件。
捐赠有助于支持我们的开源努力。