2011-12-27 43 views
3

我有一個popover從另一個popover呈現。他們都有tableViews。第一行的第二個彈出窗口很好,箭頭指向單元格的中間。但其他人指向電池的頂部,箭頭是在酥料餅的頂部,而不是在中間......從tableViewCell定位問題彈出

這就是我如何構建酥料餅

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 

self.editController = [[TitleViewController alloc] init]; 
[self.editController setSizeWithWidth:self.view.bounds.size.width AndHeight:140.0]; 
self.editController.directoryString = [directoryPath stringByAppendingPathComponent:[self.tableView cellForRowAtIndexPath:indexPath].textLabel.text]; 

self.editPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.editController]; 



CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath]; 

[self.editPopoverController presentPopoverFromRect:aFrame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 

} Here is the misplaced second popover

編輯

如果我將箭頭方向更改爲Any,它看起來像這樣。

再次回到ArrowDirection = Left

如果我做了建議修改(注意aFrame.size.height * 2,而不是除以二),箭頭指向該單元的中間,但仍然是笨拙定位在新酥料餅框架(未在中間)

enter image description here

回答

2

我認爲有這個問題2個可能的解決方案:

  1. 更改height的值至aFrame.size.height/2
  2. 更改presentPopoverFromRect:inView:permittedArrowDirections:animated:,並確保將TableViewCell'scontentView設置爲'inView'參數。

希望這會有所幫助。

+0

您最終使用哪種方式? – fatuhoku 2015-11-06 13:53:17

1

您需要確定,該行調用酥料餅什麼。當你做到了,試着用

CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath]; 

編輯取代CGRect aFrame = [self.tableView rectForRowAtIndexPath:indexPath];:固定的代碼,以反映實際的解決方案

+0

'rectForRowAtIndexPath'爲indexPath上的行返回一個rect,所以您需要以indexPath作爲參數「feed」它,而不是行... – Faser 2011-12-30 11:46:56

1

不明白爲什麼它的發生,但你不妨加(cell.frame.height/2)的酥料餅的frame.y並解決它:)

4

當我嘗試將單元格展開爲完整的tableView-size時,實際上遇到了相同的問題。詢問一個單元框架並在tableview之外使用它並不像我想象的那麼容易。然而,我在先生的一些直接問題後找到了解決方案。谷歌。

這第一種方法實際上會從tableView的角度給出單元格的框架。

CGRect rectInTableView = [myTableView rectForRowAtIndexPath:someIndexPath]; 

這是有用的,但不是完整的故事(至少不適合我)。你可能想要把這個矩形轉換成視圖,它是真正重要的。

第二種方法會將此矩形轉換爲您希望彈出窗口的視圖的角度。在我的情況下,[myTableView superView]但它可以是任何可見的視圖。

CGRect rectInSuperview = [myTableView convertRect:rectInTableView toView:someView]; 

這rectInSuperView可能是你所尋求的。它解決了我的很多cellFrame問題,它可能對你有幫助。

箭頭將始終指向矩形的中間,所以如果您的矩形工作不正常,「黑客」矩形使其符合您的需求並不是解決此問題的最佳方法。

我希望這個解決方案也適合你。如果不能隨意發表評論,我會看看我能否進一步幫助你。