2013-03-11 69 views
1

我正在尝试将重新排列控件移动到单元格的左侧。我使用自定义单元格,我的单元格有按钮。我实际上可以通过使用以下功能将它左移。但是我的右键原本就是默认的重新排序控件的位置,因此即使在应用转换之后也不可访问。不在后面的部分是可访问的。将重新排序控件移动到左侧

正如参考我已经使用了这些以下链接 http://b2cloud.com.au/how-to-guides/reordering-a-uitableviewcell-from-any-touch-point

How to make reorder control of UITableViewCell in left side?

#pragma mark - 
#pragma mark rows reordering 

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    for(UIView* view in cell.subviews) 
    { 
     if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"]) 
     { 
      UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), 48)]; 
      [resizedGripView setBackgroundColor:[UIColor whiteColor]]; 
      [resizedGripView addSubview:view]; 
      [cell addSubview:resizedGripView]; 

      // Original transform 

      const CGAffineTransform transform = CGAffineTransformMakeTranslation(40 - cell.frame.size.width, 1); 


      [resizedGripView setTransform:transform]; 
      /*for(UIImageView* cellGrip in view.subviews) 
      { 
       if([cellGrip isKindOfClass:[UIImageView class]]) 
        [cellGrip setImage:nil]; 
      }*/ 
     } 
    } 
} 

请参阅此影像http://i.stack.imgur.com/xBDLG.png

单元格中的编辑按钮是不是重新排序的原始位置访问控制。休息工作正常。

回答

1

试试这个,我希望它能帮助

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    for(UIView* view in cell.subviews) 
    { 
     if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"]) 
     { 

      UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; 
      [resizedGripView addSubview:view]; 
      [cell addSubview:resizedGripView]; 

      // Original transform 
      const CGAffineTransform transform = CGAffineTransformMakeTranslation(view.frame.size.width - cell.frame.size.width, 1); 
      // Move custom view so the grip's top left aligns with the cell's top left 

      [resizedGripView setTransform:transform]; 
     } 
    } 
} 
2

的Xcode 8.2.1, 斯威夫特3.X

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    cell.subviews.forEach() { 
     if ($0.description.range(of: "UITableViewCellReorderControl") != nil) { 
      let resizedGripView = UIView(frame: CGRect(x: 0, y: 0, width: $0.frame.maxX, height: $0.frame.maxY)) 
      resizedGripView.addSubview($0) 
      cell.addSubview(resizedGripView) 
      let transform = CGAffineTransform(translationX: $0.frame.size.width - cell.frame.size.width, y: 1) 
      resizedGripView.transform = transform 
     } 
    } 
} 
相关问题