首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewCell accessoryView帧宽/高度为零

UITableViewCell accessoryView帧宽/高度为零
EN

Stack Overflow用户
提问于 2015-02-27 02:33:17
回答 3查看 4.2K关注 0票数 4

当附件被点击时,我试图显示来自UITableViewCell accessoryView的一个accessoryView。我用:

代码语言:javascript
复制
[self.popover presentPopoverFromRect:[[tableView cellForRowAtIndexPath:indexPath] accessoryView].frame inView:tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

但是the problem:.accessoryView].frame{{0, 0}, {0, 0}},所以弹出窗口显示在屏幕的左上角。这一切为什么要发生?如何获得accessoryView的实际框架?

我正在使用的

  • iOS 8
  • 故事板
  • 预定义的详细附件(UITableViewCellAccessoryDetailButton)
  • iPad

如果你需要更多的代码来回答,请告诉我,我会给你的。提前感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-12-03 18:53:31

这是因为cell.accessoryView是空的。cell.accessoryView只返回自定义accessoryView

票数 3
EN

Stack Overflow用户

发布于 2015-03-07 20:31:03

accessoryViewUITableViewCell坐标系中的帧。您需要使用UIView:-convertRect:fromView:上的方法将其转换为UIView坐标系统。

调用[tableView convertRect:accessoryView.frame fromView:cell] // Code not tested

票数 0
EN

Stack Overflow用户

发布于 2015-04-14 17:26:29

我从来没有得到accessoryView的框架或界限,但这个组合最终允许我伪造它,得到了我需要的东西。靠近行右侧的位置(即accessoryButton,在旋转后更新弹出位置)。

代码语言:javascript
复制
- (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

代码语言:javascript
复制
- (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;
               }
          }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28756556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档