2013-03-07 56 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

相关问题