tableViewCell 定位问题的 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];
}
编辑
如果我将箭头方向更改为任意,看起来像这样。
再次回到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];
}
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 * 2
and 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当尝试将单元格扩展到完整的 tableView 大小时,我实际上遇到了同样的问题。询问单元格框架并在表格视图之外使用它并不像我想象的那么容易。然而,在向先生提出一些直接问题后,我找到了解决方案。谷歌。
第一个方法实际上将从 tableView 的角度给出单元格的框架。
这很有用,但不是完整的故事(至少不适合我)。如果拥有该矩形实际上很重要,您可能希望将该矩形转换为视图。
第二种方法会将这个矩形转换为您希望弹出窗口所在的视图的透视图。在我的例子中
[myTableView superView]
但它可以是任何可见视图。这个 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.
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.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.
我认为这个问题有 2 种可能的解决方案:
aFrame
的height
值更改为aFrame.size.height / 2
>presentPopoverFromRect:inView:permissedArrowDirections:animated
:,并确保TableViewCell's
contentView
设置为“inView
” 范围。希望这有帮助。
I think there are 2 possible solutions to this problem:
height
value ofaFrame
toaFrame.size.height / 2
presentPopoverFromRect:inView:permittedArrowDirections:animated
:, and make sure theTableViewCell's
contentView
is set as the 'inView
' parameter.Hope this helps.
不明白为什么会发生这种情况,但您也可以将 (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 :)
您需要确定该行对弹出窗口的调用。当你这样做时,尝试用编辑替换 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];
withedit: fixed the code to reflect the actual solution