[英]What is the best way to implement this scrolling UI in Objective-C?
I'm trying to implement an interface view shown in the image below. 我正在尝试实现下图所示的界面视图。
This UI is made up of three parts, the blue labels, the arrow labels, and the gray label. 该UI由三部分组成,蓝色标签,箭头标签和灰色标签。
In this UI, there are following requirements to satisfy. 在此UI中,需要满足以下要求。
At present I think it is good to implement this UI by UITableView and custom table cell. 目前,我认为通过UITableView和自定义表格单元来实现此UI是很好的。 But I'm not sure how to implement it, especially displaying arrow labels between the blue labels, appending new blue label before the gray one.
但是我不确定如何实现它,特别是在蓝色标签之间显示箭头标签,在灰色标签之前附加新的蓝色标签。
Is there a good way to implement these feature easily in UITableView? 有没有一种很好的方法可以在UITableView中轻松实现这些功能? Or, is there another way to do this, like using UIScrollView?
或者,还有其他方法可以做到,例如使用UIScrollView吗?
Your thoughts and help will be hugely appreciated. 您的想法和帮助将不胜感激。
If you are building for iOS9 you can use UIStackView, very simple to use and fits your requirement.You will have to use UIStackview with a scrollview. 如果您要针对iOS9进行构建,则可以使用UIStackView,它非常易于使用并且符合您的要求。您必须将UIStackview与scrollview结合使用。 For sample you can use the code in the below link.
对于示例,您可以使用以下链接中的代码。
https://gist.github.com/twostraws/a02d4cc09fc7bc16859c https://gist.github.com/twostraws/a02d4cc09fc7bc16859c
Don't use UIScrollView. 不要使用UIScrollView。 As the number of blue cells gets bigger, you'll use more and more memory.
随着蓝色单元格数量的增加,您将使用越来越多的内存。 Proper use UITableView ensures that your memory use stays fixed (memory from UI) as the length of the array of cells grows.
正确使用UITableView可确保随着单元格数组长度的增加,内存使用保持固定(UI的内存)。
You have two fundamental options here: 您在这里有两个基本选择:
Multiple sections, or a single section. 多个部分,或单个部分。
With multiple sections, each UITableViewCell is a blue cell. 具有多个部分,每个UITableViewCell是一个蓝色单元格。 Use UITableViewSectionFooter for the arrow cell.
将UITableViewSectionFooter用于箭头单元格。 This guarantees that there will always be on arrow cell per blue cell.
这样可以确保每个蓝色单元格始终有一个箭头单元格。
With a single section, the number of cells = #ofbluecells * 2. Then, use indexPath.row % 2 to decide whether or not to dequeue a blue cell or arrow cell. 在单个部分中,单元数= #ofbluecells *2。然后,使用indexPath.row%2决定是否出队蓝色单元格或箭头单元格。
Regardless of which approach you go with, you should use a UITableViewFooterView for the 'add new cell' behavior. 无论采用哪种方法,都应使用UITableViewFooterView进行“添加新单元格”行为。
In either approach, you can delete cells by updating the data model (most likely an array) then calling [tableView beginUpdates]; 无论采用哪种方法,都可以通过更新数据模型(很可能是数组)然后调用[tableView beginUpdates]来删除单元格; [tableViewDeleteRowsAtIndexPaths:];
[tableViewDeleteRowsAtIndexPaths:]; [tableView endUpdates];
[tableView endUpdates];
To insert a new blue cell, same as delete except you add to your array. 要插入一个新的蓝色单元格,与删除相同,只不过要添加到数组中。
In either approach, you don't have to manage a separate array of arrow cells. 无论采用哪种方法,都不必管理单独的箭头单元阵列。 If tapping on an arrow cell does nothing, I would personally go the route of 1 section per blue cell.
如果点击箭头单元格无济于事,我个人将每个蓝色单元格分成1个部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.