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

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

问题描述

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



我在github和Google上找到了很多答案。但是,仍然不能满足我的要求。



实际上我想添加两个表视图。



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



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



所有商店和数据都将从json获取。



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



有帮助吗?



更新:请看看



解决方案

@TechBee提供的答案适用于那些对不使用节和使用感兴趣的节的节



可以使用 UITableView 在Swift中实现手风琴菜单以一种非常简单的方式,仅具有两个单元格,一个用于父级单元格,另一个用于子级单元格,并随时保持对单元格的跟踪扩展或折叠,因为它可以更改 indexPath.row

使用功能 insertRowsAtIndexPaths(_:withRowAnimation:) deleteRowsAtIndexPaths(_:withRowAnimation:) 始终位于对 tableView.beginUpdates() tableView.endUpdates()并更新数据源中的项目总数或模拟它的更改,我们可以通过动画非常简单的方式实现在 UITableView 中插入删除新单元格的操作



我已经在Github中实现了自己的存储库,其中包含上述所有 AccordionMenu 以简单易懂的方式使用Swift和 UITableView 。它允许几个单元扩展,一次只能扩展一个。


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.

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)

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

All the store and data will got from json.

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.

UPDATE : Please take a look

解决方案

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

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.

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.

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天全站免登陆