本文介绍了iOS 中 UITableView 中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 iOS 中创建这种类型的 tableview??

在这里,如果我们点击第一行帐户",它会自动滚动显示在图像中的更多行.如果我们再次点击帐户",则该视图将被隐藏.

Here, If we tap on 1st row 'Account', then automatically it scrolled with some more rows which is showing in Image.And if again we tap on Account, then that view will be hidden.

推荐答案

您可以将帐户作为一个单元格,在点击时展开以显示三个按钮(个人资料"、激活帐户"、更改密码"),但是产生了一个问题:点击三个按钮中的每一个都将计为用户选择了帐户单元格"并触发 -tableView:didSelectRowAtIndexPath: 并导致单元格的展开/折叠.

You could have Account as a cell that expands on tap to reveal three buttons ("Profile", "Activate Account", "Change Password"), but that creates a problem: tapping around each of the three buttons will count as "user selected the Account cell" and trigger -tableView:didSelectRowAtIndexPath: with the resulting expand/collapse of the cell.

或者您可以将每个隐藏选项(配置文件"、激活帐户"、更改密码")设为单独的表格视图单元格.但我不知道如何为三个单元格制作动画整体扩展和收缩(而不是每个单元格分别从零高度扩展到完全扩展).

Or you could make each of the hidden options ("Profile", "Activate Account", "Change Password") a separate table view cell. But I don't know how you could animate the three cells as a whole expanding and contracting (instead of each expanding separately from zero height to fully expanded).

因此,也许最好的解决方案是:

  1. 偶数单元格(索引:0、2、4...)同时扮演菜单标题"和切换菜单打开/关闭"的角色(朝向相关的奇数单元格如下面所描述的).
  2. 在奇数索引(1、3, 5 ...).使用 target-action 响应用户选择每个选项/按钮.
  3. 实现表格视图委托方法,以便只有偶数单元格(菜单标题)是可选的,并实现选择逻辑来展开/折叠相应的奇数单元格(在 -tableView:didSelectRowAtIndexPath: 中).例如,选择索引 0 处的单元格(帐户")会导致展开/折叠索引 1 处的单元格(带有个人资料"、激活帐户"、更改密码"选项的菜单).
  1. Have the even cells (indices: 0, 2, 4...) to fulfil both the role of "Menu title" and "Toggle menu open/close" (towards the associated odd cells described below).
  2. Interleave the (initially collapsed) "menu body" cells, each with one button per option (e.g. "Profile", "Activate Account", "Change Password"), laid out vertically, in the odd indices (1, 3, 5...). Use target-action to respond to the user selecting each option/button.
  3. Implement the table view delegate method so that only the even cells (menu headers) are selectable, and implement selection logic to expand/collapse the corresponding odd cell (inside -tableView:didSelectRowAtIndexPath:). For example, selecting the cell at index 0 ("Account") results in expanding/collapsing the cell at index 1 (menu with options "Profile", "Activate Account", "Change Password").

这不是 UITableView 最优雅的用法,但可以完成工作.

It is not the most elegant use of UITableView, but will get the job done.

这篇关于iOS 中 UITableView 中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:10