简体   繁体   English

在Objective-C中实现此滚动UI的最佳方法是什么?

[英]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. 我正在尝试实现下图所示的界面视图。

UI Image UI图片

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中,需要满足以下要求。

  • The label view(the blue one) and the arrow label are shown in turn 标签视图(蓝色)和箭头标签依次显示
  • The blue labels can change its positions each other (like UITableView) 蓝色标签可以相互更改其位置(如UITableView)
  • List item can be deleted 列表项可以删除
  • By tapping the gray label, a new blue label appear and append after the last blue label that is already shown in. 通过点击灰色标签,会出现一个新的蓝色标签,并将其附加在已显示的最后一个蓝色标签之后。

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.

相关问题 在Objective-C中以特定间隔增加NSDateComponents的最佳方法是什么? - What is the best way to increment NSDateComponents in specific intervals in Objective-C? 硬编码这些数据的最佳方法是什么? Objective-C的 - What is the best way of hardcoding this data. Objective-C 在Objective-C中定义常量的最佳方法 - Best way to define Constants in Objective-C 如何实现像iCarousel Rotary类型,Objective-C这样的UI? - How to implement UI like iCarousel Rotary type, Objective-C? 使用Objective-C,在没有API的情况下,登录服务并从结果页面中抓取内容的最佳方法是什么? - With Objective-C, what is the best way to log in to a service and scrape content from the resulting page without an API? 获取链接并消除所有混乱,仅关注内容-在Objective-C中做到这一点的最佳方法是什么? - Get a link and removing all the clutter and only focusing on the content - what's the best way to do this in Objective-C? Objective-C UIScrollView无法滚动 - Objective-C UIScrollView not scrolling 在Objective-C iOS应用中创建用户身份验证的最佳方法 - Best way to create an user authentication in Objective-C iOS App 简化/重构表的最佳方法查看Objective-C中的代码设置 - Best way to simplify/refactor tableView code setup in objective-c 保存自定义Objective-c对象的层次结构以实现持久性的最佳方法 - Best way to save a hierarchy of custom Objective-c objects for persistence
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM