2015-02-27 3 views
4

Я пытаюсь показать UIPopoverController с помощью аксессуаровUITableViewCellПросмотрите, когда аксессуар забит. Я использую:UITableViewCell accessoryView frame width/height zero

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

Но проблема: ... accessoryView].frame является {{0, 0}, {0, 0}}, поэтому поповер показывает в верхнем левом углу экрана. Почему это происходит? Как получить реальный фрейм аксессуара?


Я использую:

  • IOS 8
  • Storyboards
  • предопределенная Деталь Аксессуар (UITableViewCellAccessoryDetailButton)
  • IPad

Пожалуйста, дайте мне знать, если вам нужен еще один код для ответа, и я постараюсь получить его для вас. Заранее спасибо!

+0

Пробовали ли вы показывать его непосредственно с точки зрения аксессуар? Если вы не обрезая его подвидов из ячейка должна работать: '[self.popover presentPopoverFromRect: [[tableView cellForRowAtIndexPath: indexPath] accessoriesView] .frame inView: [[tableView cellForRowAtIndexPath: indexPath] accessoriesView] allowedArrowDirections: UIPopoverArrowDirectionAny animated: YES];' – Raspu

+0

@Raspu Нет, didn Не работай. – ricky3350

ответ

3

это потому, что cell.accessoryView является недействительным. cell.accessoryView возвращает только пользовательские accessoryView.

0

Рамка accessoryView в пределах UITableViewCell Система координат. Вам необходимо преобразовать его в систему координат TableView, используя метод UIView: -convertRect:fromView:.

Вызов [tableView convertRect:accessoryView.frame fromView:cell] // Code not tested

+0

Не работает, к сожалению. – ricky3350

+0

что у вас получилось? получил код, на который я могу смотреть? – Yariv

0

Я никогда не получал кадра или границ для 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; 
       } 
      } 
    } 
} 
Смежные вопросы