如何将uitableview选择与indexpath值居中

发布于 2024-12-08 11:14:10 字数 573 浏览 7 评论 0原文

我正在保存子视图中的 indexPath 选择,并使用委托将其传递到父视图。当我从主视图返回子视图时,我将 indexPath 传递回它,并向用户显示他们之前在 tableviewcell 的附件视图中选择的单元格。

一个问题是,如果用户从相当大的列表中选择了一个单元格,则很难找到他们再次选择的单元格,以防他们想要更改它(因为他们犯了一个错误)

我想知道他们是否是一种方法使用indexPath或类似的东西将uitableview的先前选择的单元格居中到屏幕的中心?

更新::

这是我试图实现的图形视图,以使其更容易理解。

第一步:选择单元格,然后转到子视图并选择要传递回主视图的单元格(值)(保存indexPath)所选单元格的) 在此处输入图像描述

第二步:用户要么想要更改他的选择,要么犯了一个错误,需要选择下面的单元格他们选择的那个...重复前面的步骤,但在视图中心显示先前选择的单元格。

在此处输入图像描述

I am saving the indexPath selection from a subview and passing it to the parent view with delegates. When I got back to my subview from my main view I pass the indexPath back to it and show the user which cell they previously selected with a tick in the accessory view of the tableviewcell.

One problem being if the user has selected a cell out of a fairly big list its hard to find the cell they selected again incase they wanted to change it (being that they made a mistake)

I would like to know if their is a way to use indexPath or something similar to center the previously selected cell of the uitableview to the center of the screen?

UPDATE::

Here is a graphical view of what I am trying to achive to make it abit more understandable..

step one : select cell then go to subview and select the cell (value) you want to pass back to main view (save indexPath of selected cell)
enter image description here

step two: user either wants to change his selection or made a mistake and was ment to select the cell below the one they chose... repeat previous steps but display previously selected cell in the center of the view..

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慵挽 2024-12-15 11:14:10

您是否尝试过以下功能

[tableView scrollToRowAtIndexPath: atScrollPosition:UITableViewScrollPositionMiddle animated:YES]

Have you tried the following function

[tableView scrollToRowAtIndexPath: atScrollPosition:UITableViewScrollPositionMiddle animated:YES]
不离久伴 2024-12-15 11:14:10

UITableView 是 UIScrollView 的子类 - 尝试设置内容偏移量(通过单元格高度和索引路径计算出多少)。

[tableView setContentOffset:CGPointMake(0, indexPath.row*cellHeight) animated:YES];

应该有效。您可能想要稍微不同地进行数学计算。

a UITableView is a subclass of UIScrollView - try setting the Content Offset (figure out how much with the cell height and indexPath).

[tableView setContentOffset:CGPointMake(0, indexPath.row*cellHeight) animated:YES];

should work. You might want to do the math a little differently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文