快速制作简单的手风琴 TableView? [英] Making Simple Accordion TableView in swift?

查看:16
本文介绍了快速制作简单的手风琴 TableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以像 Calendar Event Create 那样快速制作简单的手风琴视图?我不想使用其他第三方库以及其他代码.

Is there any way that I can make simple Accordion View in swift like the one at Calendar Event Create? I don't want to use other third party library as well as other code.

我在 github 和 google 上找到了很多答案.但是,还是达不到我的要求.

I found many answer at github and over google. But,still don't meet my requirement.

其实我想添加两个表格视图.

Actually I want to add two table view.

第一个是显示城市的部分,例如(纽约、洛杉矶、拉斯维加斯等)

The first one is section which show City such as (New York,Los Angles,Las Vegas,etc)

当我点击其中一个城市时,它会在 tableview 中显示商店地址,这意味着有很多商店.

When I tapped one of the city,it will show store address in tableview which mean there are many stores.

所有的存储和数据都来自json.

All the store and data will got from json.

我想做的手风琴视图与 iOS 上的日历应用程序中的一样简单.但是,我要插入到两个动态的 tableView(每个部分内的部分标题和内部记录)中的数据.

The accordion view that i want to do is as simple as the one at Calendar App on iOS. But,the data that I gonna insert into two tableView (Section Header & Inner Records inside each section) which is dynamic.

有什么帮助吗?请指导我,帮帮我.

Any Help? Please Guide me,Help me out.

更新:请看

推荐答案

@TechBee 提供的答案对于那些有兴趣不使用部分和使用单元格的人来说,可以很好地使用部分.

The answer provided by @TechBee works fine using sections for those interested in not using sections and use cells.

可以使用 UITableView 以一种非常简单的方式在 Swift 中实现 Accordion Menu,只需有两个单元格,一个用于父单元格,另一个用于子单元格单元格,并在每一刻保持单元格展开或折叠的轨迹,因为它可以在每次展开或折叠新单元格时更改 indexPath.row.

The implementation of an Accordion Menu in Swift can be achieved using UITableView in a very simple way, just having two cells one for the parent cells and another for the childs cells and in every moment keep the track for the cells expanded or collapsed because it can change the indexPath.row every time a new cell is expanded or collapsed.

使用函数 insertRowsAtIndexPaths(_:withRowAnimation:)deleteRowsAtIndexPaths(_:withRowAnimation:) 总是在对 tableView.beginUpdates()tableView.endUpdates() 和更新数据源中的项目总数或模拟它的变化我们可以实现插入删除新单元格在UITableView 以非常简单的方式包含动画.

Using the functions insertRowsAtIndexPaths(_:withRowAnimation:) and deleteRowsAtIndexPaths(_:withRowAnimation:) always inside a block of call to tableView.beginUpdates() and tableView.endUpdates() and updating the total of items in the data source or simulating it changes we can achieve the insertion of deletion of new cells in the UITableView in a very easy way with animation included.

我已经使用 Swift 和 AccordionMenu>UITableView 以一种简单易懂的方式.它允许扩展多个单元格或一次只扩展一个单元格.

I've implemented myself a repository in Github with all the explained above AccordionMenu using Swift and UITableView in a easy and understandable way. It allows several cells expanded or only one at time.

这篇关于快速制作简单的手风琴 TableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆