首页 > 解决方案 > UITableViewCell 与下拉 UITableView

问题描述

我正在使用具有“n”行数的 UITableView。在每个单元格中,我都有一个菜单按钮。当我单击菜单按钮时,我需要在每个单元格中显示一个包含 3 行的下拉 UITableView。如何设置下拉 UITableView 的框架。我正在使用目标c。

在此处输入图像描述

当我单击菜单按钮时,我需要在每个单元格的菜单按钮下方显示报告 UITableView

标签: iosobjective-c

解决方案


这有点复杂,但并不难。幸运的是,我们有一个名为DropDown的库。这使得这项任务非常容易。

添加pod 'DropDown'到您的 Podfile。

let dropDown = DropDown()

// The view to which the drop down will appear on
dropDown.anchorView = view // UIView or UIBarButtonItem in your case that menu button

// The list of items to display. Can be changed dynamically
dropDown.dataSource = ["Report"]

dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
  print("Selected item: \(item) at index: \(index)")
}
dropDown.show()

在 Objective-C 中

DropDown *dropDown = [[DropDown alloc] init];
dropDown.selectionAction = ^(NSInteger, NSString * _Nonnull) {
    //code
};

Swift 中的库,但您可以使用桥接头在 Objective C 中使用它。希望这会对您有所帮助


推荐阅读