UITableViewCell accessoriesView frame width / zero height

I try to show UIPopoverControllerfrom the accessory UITableViewCellwhen connecting the accessory. I use:

[self.popover presentPopoverFromRect:[[tableView cellForRowAtIndexPath:indexPath] accessoryView].frame inView:tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

But the problem : ... accessoryView].frameis equal {{0, 0}, {0, 0}}, so the popover is displayed in the upper left corner of the screen. Why is this happening? How to get the actual frame of the accessory?


I use:

  • iOS 8
  • Storyboard
  • Predefined Optional Accessory ( UITableViewCellAccessoryDetailButton)
  • iPad

Please let me know if you need another code for an answer, and I will try to get one for you. Thanks in advance!

+4
source share
3 answers

cell.accessoryView null. cell.accessoryView accessoryView.

+3

accessoryView UITableViewCell. TableView, UIView: -convertRect:fromView:.

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

0

, , . (, , popover .

- (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 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 on after rotate willRepositionPopoverToRect
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}

, popover . 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;
               }
          }
    }
}
0

All Articles