2011-04-18 67 views
3

我想以编程方式选择表格视图中的行,然后呈现我的弹出窗口并让箭头指向单元格。通过UITableViewCell的UIPopoverController

此代码在表格没有滚动时工作正常,对于滚动表视图弹出窗口箭头位置不正确。

[self.EventsTableView selectRowAtIndexPath:indexPath 
            animated:YES 
          scrollPosition:UITableViewScrollPositionMiddle]; 

[popoverController presentPopoverFromRect:CGRectOffset(cell.frame, 0, cell.frame.size.height + self.EventsTableView.contentOffset) 
            inView:self.view  
       permittedArrowDirections:UIPopoverArrowDirectionLeft 
           animated:YES]; 

感谢所有帮助

回答

6

你应该通过对小区的视图。很可能你会想要传递单元格的边界(cell.bounds,而不是cell.frame)。

+0

正确,良好的答案 只需: [popoverController presentPopoverFromRect:cell.bounds inView:细胞permittedArrowDirections:UIPopoverArrowDirectionLeft动画:YES]; 谢谢。 – Ashraf 2011-04-18 17:18:08

+0

我仍然需要处理不可见的行! – Ashraf 2011-04-18 17:27:47

+0

你的意思是当一个单元格以不可见的方式滚动时?在这种情况下,您可能希望使用'scrollToRowAtIndexPath:atScrollPosition:animated:'将其移动到视图中。 – 2011-04-18 23:23:18

3

上面的方法似乎没有为我工作,当用户滚动列表下来。找到相对于滚动量的单元格位置是个诀窍。

CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath] 
    toView:tableView]; 

[popoverController presentPopoverFromRect:rect 
    inView:tableView 
    permittedArrowDirections:UIPopoverArrowDirectionAny 
    animated:YES];