iPhone - 将选定的单元格移动到 uitableview 的顶部
我寻找这个问题,但我不相信我能找到答案。我有一个自定义单元格的表格视图,单击该单元格时,所选单元格会推送包含信息的新单元格。我想知道是否有人知道如何将选定的单元格推到 uitableview 的顶部,或者让它填满整个表格视图。
我的 uitableview 只占据屏幕的一半,我希望当选择单元格时它只占据屏幕的一半,并且用户仍然能够滚动单元格(如果有意义的话)?
任何建议将不胜感激,描述我正在寻找的东西有点困难,所以如果有人需要澄清,请随时问我。
I looked for this problem and I don't believe I could find an answer. I have a tableview of custom cells that when clicked, the selected cell pushes a new cell with information. I was wondering if anyone had an idea of how to push the selected cell to the top of the uitableview, or make it fill up the entire tableview.
My uitableview only takes up half of the screen, and I wish for when the cell is selected that it only take up that half of the screen, and the user is still able to scroll the cell (if that makes sense)?
Any suggestions would be appreciated, it was somewhat difficult to describe what I am looking for, so if anyone needs clarification please do not hesitate to ask me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 cellForRowAtIndexPath 中,您需要在创建单元格后将其放置在
单元格的自定义高度中,这对我来说也很有效。
in cellForRowAtIndexPath, you need to place this in after you have created your cell
This did the trick for me with the custom height of the cells as well.
在我的应用程序中,我有一堆单元格,单击时会扩展得更大;并且一次只能扩展 1 个单元格。我基本上跟踪当前选定的indexPath,然后在heightForRowAtIndexPath:中检查这是否是选定的sell;如果是的话我返回一个更大的高度。
然后,在 didSelectRowAtIndexPath: 中,我只是设置当前的 indexPath,并重新加载新单元格和前一个单元格。这听起来与您正在寻找的类似......这有用吗?
In my app I have a bunch of cells that expand to be larger when clicked; and only 1 cell can be expanded at a time. I basically keep track of the current selected indexPath, and then in heightForRowAtIndexPath: check to see if this is the selected sell; if it is I return a larger height.
Then, in didSelectRowAtIndexPath: I just set the current indexPath, and reload both the new cell and the previous one. This sounds similar to what you are looking for... would that work?
要将所选单元格移动到表格视图的顶部,您可以将所选单元格的索引存储在 didSelectRowAtIndexPath 的实例变量中,然后调用 [tableView reloadData]。
在数据源的 tableView:cellForRowAtIndexPath: 方法中,您将确保为索引 0 返回所选单元格,并为其索引 + 1 返回所选单元格之前的所有单元格。
To move the selected cell to the top of the tableview, you could store the selected cell's index in an instance variable in didSelectRowAtIndexPath, and then call [tableView reloadData].
In your datasource's tableView:cellForRowAtIndexPath: method, you would ensure that the selected cell is returned for index 0 and all cells prior to the selected cell are returned for their index + 1.
如果您想移动单元格,您可以从这里开始。
这会将行移动到 UITableView 所关注的范围内。当然,您还需要匹配数据源中的新订单。 (就像更改数据数组中的顺序一样)
此外,执行此操作时,您可能希望将表格滚动到顶部。
If you are looking to move the cell, this is a base you could start from.
This will move the row as far as the UITableView is conserned. Of course you'll need to match the new order in the data source also. (Like changing the order in your array of data)
Also, you'll probably want to scroll the table to the top when you do this.