当附件被点击时,我试图显示来自UITableViewCell accessoryView的一个accessoryView。我用:
[self.popover presentPopoverFromRect:[[tableView cellForRowAtIndexPath:indexPath] accessoryView].frame inView:tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];但是the problem:.accessoryView].frame是{{0, 0}, {0, 0}},所以弹出窗口显示在屏幕的左上角。这一切为什么要发生?如何获得accessoryView的实际框架?
我正在使用的:
UITableViewCellAccessoryDetailButton)如果你需要更多的代码来回答,请告诉我,我会给你的。提前感谢!
发布于 2015-12-03 18:53:31
这是因为cell.accessoryView是空的。cell.accessoryView只返回自定义accessoryView。
发布于 2015-03-07 20:31:03
accessoryView在UITableViewCell坐标系中的帧。您需要使用UIView:-convertRect:fromView:上的方法将其转换为UIView坐标系统。
调用[tableView convertRect:accessoryView.frame fromView:cell] // Code not tested
发布于 2015-04-14 17:26:29
我从来没有得到accessoryView的框架或界限,但这个组合最终允许我伪造它,得到了我需要的东西。靠近行右侧的位置(即accessoryButton,在旋转后更新弹出位置)。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
StackPropertiesTableViewController *stackPropertiesTableViewController = [[StackPropertiesTableViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:stackPropertiesTableViewController];
self.stackPropertiesPopoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
[self.stackPropertiesPopoverController setDelegate:self];
TableViewCell *cell = (TableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
// Works for faking the display from Info accessoryView, but doesn't update it's location after rotate
CGRect contentViewFrame = cell.contentView.frame;
CGRect popRect = CGRectMake(contentViewFrame.origin.x + contentViewFrame.size.width, contentViewFrame.size.height/2.0, 1, 1);
[self.stackPropertiesPopoverController presentPopoverFromRect:popRect inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
// Need this so popover knows which row it's on after rotate willRepositionPopoverToRect
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}这是需要更新的位置,相对于行宽度旋转后的弹出式。不要忘记声明UIPopoverControllerDelegate
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing *)view
{
if (self.stackPropertiesPopoverController == popoverController)
{
NSIndexPath *itemPath = self.tableView.indexPathForSelectedRow;
if (itemPath)
{
TableViewCell *cell = (TableViewCell *)[self.tableView cellForRowAtIndexPath:itemPath];
if (cell)
{
CGRect contentViewFrame = cell.contentView.frame;
CGRect popRect = CGRectMake(contentViewFrame.origin.x + contentViewFrame.size.width, contentViewFrame.size.height/2.0, 1, 1);
*rect = popRect;
}
}
}
}https://stackoverflow.com/questions/28756556
复制相似问题