2013-03-07 34 views
0

我想重新排序圖(三線)將被顯示在一個UITableViewCell的左側,因爲右側將通過覆蓋UIView的隱藏。有左側的符號重新排序在一個UITableViewCell

這段代碼,我發現:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    for(UIView* view in cell.subviews) 
    { 
     if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"]) 
     { 
      // Creates a new subview the size of the entire cell 
      UIView *movedReorderControl = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; 
      // Adds the reorder control view to our new subview 
      [movedReorderControl addSubview:view]; 
      // Adds our new subview to the cell 
      [cell addSubview:movedReorderControl]; 
      // CGStuff to move it to the left 
      CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height); 
      CGAffineTransform transform = CGAffineTransformIdentity; 
      transform = CGAffineTransformTranslate(transform, -moveLeft.width, -moveLeft.height); 
      // Performs the transform 
      [movedReorderControl setTransform:transform]; 
     } 
    } 
} 

工作得很好,當表被加載的第一次。 然而,當細胞獲得「重繪」(滾動脫穎而出,回來時等)重新排序符號就會消失。

什麼問題?

+0

如果你把你的疊加視圖細胞的內容查看(像你應該)和重疊視圖適度調整是根據它的父視圖的大小大小被改變,那麼當重排序控件出現時,覆蓋視圖會自動調整,因爲單元格的contentView被調整大小以爲重排控件騰出空間。無需編寫可能在未來iOS更新中破解的代碼(或因專用API使用而被拒絕)。 – rmaddy 2013-03-07 02:24:40

+0

謝謝你的評論maddy。但是,這是如何使用私人API?你能否給出代碼示例,以及如何以正確的方式做到這一點? – 2013-03-07 08:56:58

+0

您對'UITableViewCellReorderControl'基準可能被認爲是使用由蘋果私有API的。即使不是這樣,代碼也非常脆弱,可能會從任何iOS更新中突破。挖掘框架提供的類的未公開的視圖結構絕不是一個好主意。 – rmaddy 2013-03-07 15:55:30

回答

1

你不斷移動相對於當前位置的重新排序控制

CGSize moveLeft = CGSizeMake(movedReorderControl.frame.size.width - view.frame.size.width, movedReorderControl.frame.size.height - view.frame.size.height); 

所以它看起來像它的移動它關閉屏幕。嘗試存儲初始的框架,然後使用該改變你的子視圖:

CGSize moveLeft = CGSizeMake(initialFrame.width - view.frame.size.width, initialFrame.width.height - view.frame.size.height); 
0

的代碼應該在的UITableView細胞的drawRect:方法走得如此,每當細胞更新,它被稱爲。應該是細胞的責任,而不是觀點。

+0

同樣的效果。沒有什麼變化。 – 2013-03-07 00:52:25

相關問題