iOS 中 UITableView 中的下拉列表

编程入门 行业动态 更新时间:2024-10-26 02:32:05
本文介绍了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).

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

  • 让偶数单元格(索引:0、2、4...)同时扮演菜单标题"和切换菜单打开/关闭"的角色(朝向相关的奇数单元格如下面所描述的).
  • 在奇数索引(1、3, 5 ...).使用 target-action 响应用户选择每个选项/按钮.
  • 实现表格视图委托方法,以便只有偶数单元格(菜单标题)是可选的,并实现选择逻辑来展开/折叠相应的奇数单元格(在 -tableView:didSelectRowAtIndexPath: 中).例如,选择索引 0 处的单元格(帐户")会导致展开/折叠索引 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).
  • 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.
  • 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 中的下拉列表

    本文发布于:2023-08-05 16:59:26,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1306820.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:列表   iOS   UITableView

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!