ios - 快速滑出带有子类别的栏
问题描述
表格视图中有一些行。每行打开一个新视图。现在我想在单击特定行时显示一些子类别。每个子类别都会打开不同的视图。我只使用 1 个部分。有任何想法吗?
解决方案
只需这样做。
class CategoriesListViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var filterCategories = [CategoryViewModel]()
override func viewDidLoad() {
super.viewDidLoad()
tfSearch.placeholder = LocalizeKey.search.localized
getCategories()
// Do any additional setup after loading the view.
}
extension CategoriesListViewController : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filterCategories.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CategoryCellTableView
let category = filterCategories[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let controller : SubCategoriesListViewController = ViewControllerManager.shared.find() {
controller.selectedCategory = self.filterCategories[indexPath.row]
self.pushViewController(controller : controller)
}
}
子类别将从主要类别中子类化并覆盖表视图选择方法并执行您想做的任何事情。
class SubCategoriesListViewController: CategoriesListViewController {
@IBOutlet weak var tableView: UITableView!
var filterCategories = [CategoryViewModel]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let controller = DifferentViewController()
self.pushViewController(controller : controller)
}
推荐阅读
- java - Java 过滤器适用于一个谓词,但不适用于另一个谓词
- java - 如何从 swt.SelectionListener 中找到事件类型?
- laravel - Laravel Eloquent:在主要语句上应用“with where”过滤器
- jquery - 根据表单输入数创建多维数组
- jquery - JQuery 3.4.1 支持哪个版本的 bootstrap
- docker - 具有特定用户的 Gitlab CI 作业
- javascript - 哈希链接与导航菜单不匹配
- swift - 在 Swift 5 中的 applicationWillResignActive 中显示图像
- flutter - 如何防止关闭 CupertinoActionSheet/showCupertinoModalPopup?
- c# - Sage 200:无法将许多 *.dll 文件添加到我的 Visual Studio C# 项目中以使 Sage 200 基本功能正常工作