tableViewCell 定位问题的 Popover

发布于 2024-12-23 09:21:32 字数 1240 浏览 2 评论 0原文

我有一个弹出窗口,它是从另一个弹出窗口呈现的。他们都有表视图。第一行的第二个弹出窗口很好,箭头指向单元格的中间。但其他指向单元格的顶部,箭头位于弹出窗口的顶部,而不是中间......

这就是我构建弹出窗口的方式

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

self.editController = [[TitleViewController alloc] init];
[self.editController setSizeWithWidth:self.view.bounds.size.width AndHeight:140.0];
self.editController.directoryString = [directoryPath stringByAppendingPathComponent:[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text];

self.editPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.editController];



CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

[self.editPopoverController presentPopoverFromRect:aFrame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

} 这是放错位置的第二个弹出窗口

编辑

如果我将箭头方向更改为任意,看起来像这样。

再次回到ArrowDirection = Left

如果我进行了建议的更改(请注意aFrame.size.height * 2并且不除以二),则箭头指向单元格的中间,但仍然尴尬地定位在新的弹出框框架中(不在中间)

在此处输入图像描述

I have a popover which is presented from another popover. They both have tableViews. The second popover for the first row is fine, the arrow is pointing to the middle of the cell. But the others point to the top of the cell, and the arrow is at the top of the popover, not in the middle …

Thats how i construct the popover

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

self.editController = [[TitleViewController alloc] init];
[self.editController setSizeWithWidth:self.view.bounds.size.width AndHeight:140.0];
self.editController.directoryString = [directoryPath stringByAppendingPathComponent:[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text];

self.editPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.editController];



CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

[self.editPopoverController presentPopoverFromRect:aFrame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

}
Here is the misplaced second popover

EDIT

IF I change Arrow Direction to Any, it looks like this.

Back again to ArrowDirection = Left

If I make the changes that were recommended (note that aFrame.size.height * 2and not divided by two), the arrow points to the middle of the cell, but still is awkwardly positioned in the new popover frame (not in the middle)

enter image description here

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

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

发布评论

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

评论(4

意中人 2024-12-30 09:21:32

当尝试将单元格扩展到完整的 tableView 大小时,我实际上遇到了同样的问题。询问单元格框架并在表格视图之外使用它并不像我想象的那么容易。然而,在向先生提出一些直接问题后,我找到了解决方案。谷歌。

第一个方法实际上将从 tableView 的角度给出单元格的框架。

CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath];

这很有用,但不是完整的故事(至少不适合我)。如果拥有该矩形实际上很重要,您可能希望将该矩形转换为视图。

第二种方法会将这个矩形转换为您希望弹出窗口所在的视图的透视图。在我的例子中 [myTableView superView] 但它可以是任何可见视图。

CGRect rectInSuperview = [myTableView convertRect:rectInTableView toView:someView];

这个 rectInSuperView 可能就是您所寻找的。它解决了我的很多 cellFrame 问题,也可能对你有帮助。

箭头将始终指向矩形的中间,因此如果您的矩形不能正常工作,“破解”矩形以使其满足您的需求并不是解决此问题的最佳方法。

我希望这个解决方案也适合您。如果没有,请随时发表评论,我会看看是否可以进一步帮助您。

I actually encountered somewhat the same problem, when trying to expand a cell to full tableView-size. Asking a cell frame and use it outside the tableview isn't as easy as I thought it was. Yet I found the solution after some direct questions at mr. Google.

This first method will actually give the frame of the cell from perspective of the tableView.

CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath];

This is useful but not the complete story (at least is wasn't for me). You might want to translate that rect to the View were it actually matter to have that rect.

This second method will translate this rect to the perspective of the view where you want the popover to be. In my case [myTableView superView] but it can be any visible view.

CGRect rectInSuperview = [myTableView convertRect:rectInTableView toView:someView];

This rectInSuperView is probably what you seek. It solved a lot of my cellFrame issues and it might as well help for you.

The arrow will always point at the middle of a rect so if your rect isn't working fine "hacking" the rect to make it fit your needs isn't the best way to solve this problem.

I hope this solution works for you too. And if not feel free to leave a comment and I'll see if I can help you further.

向地狱狂奔 2024-12-30 09:21:32

我认为这个问题有 2 种可能的解决方案:

  1. aFrameheight 值更改为 aFrame.size.height / 2
  2. 更改 >presentPopoverFromRect:inView:permissedArrowDirections:animated:,并确保 TableViewCell's contentView 设置为“inView” 范围。

希望这有帮助。

I think there are 2 possible solutions to this problem:

  1. Change the height value of aFrame to aFrame.size.height / 2
  2. Change the presentPopoverFromRect:inView:permittedArrowDirections:animated:, and make sure the TableViewCell's contentView is set as the 'inView' parameter.

Hope this helps.

终难愈 2024-12-30 09:21:32

不明白为什么会发生这种情况,但您也可以将 (cell.frame.height/2) 添加到弹出窗口的frame.y 中并修复它:)

can't see why it's happening but you may as well add (cell.frame.height/2) to the popover's frame.y and fix it :)

玉环 2024-12-30 09:21:32

您需要确定该行对弹出窗口的调用。当你这样做时,尝试用编辑替换 CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

:修复代码以反映实际的解决方案

You need to determine, what the row calls to popover. When you did it, try to replace CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath]; with

CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];

edit: fixed the code to reflect the actual solution

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