2015-11-04 50 views
0

所以我這樣做我的表視圖控制器中的滾動編程到我的第一個單元格。UITableViewScrollPosition後查找UITableViewCell的UIView的框架

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
       [self.tableView scrollToRowAtIndexPath:indexPath 
            atScrollPosition:UITableViewScrollPositionBottom 
              animated:YES]; 

然後我想獲取該視圖的新的幀:

NSArray *a=[self.tableView visibleCells]; 
UIView *view = [a firstObject]; 

然而,框架,這種觀點給我(這是在我的單元陣列的第一個)返回的位置在滾動發生之前。

我試圖把它在一個動畫塊,以確保它已完成滾動它試圖找到它的位置

回答

0

框架總是與超級視圖之前。如果您有興趣,請調試(或打印出)單元格視圖的超級視圖。這不是直接的表格視圖。 (用於iOS 7或8左右,但現在嵌入在與單元格一起滾動的某個查看對象中。)

您可以嘗試獲取其超級視圖的框架。 但是,如果是標準UITableViewController,您可以將單元格的原點與基準視圖(self.viewUIViewController的角度來看是UITableView)進行比較。爲此,您可以使用convertPoint:fromViewconvertPoint:toView方法。

0

因此,原來這是因爲我有它包裹在一個動畫的動畫內等之前檢查該幀的第二動畫未完成:

[UIView animateWithDuration:0.5 animations:^{ 

       NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
       [self.tableView scrollToRowAtIndexPath:indexPath 
            atScrollPosition:UITableViewScrollPositionBottom 
              animated:NO]; 

      }completion:^(BOOL finished) 
      { 
       NSArray *a=[self.tableView visibleCells]; 
       InstructionView *iv = [[InstructionView alloc] initWithTargetView:[a firstObject] andInstructionType:kNeedYouInstruction]; 
       iv.delegate = self; 
       [iv show]; 
      }]; 

改變第二動畫NO停止了我的問題:D