2013-03-11 70 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 
     } 
    } 
} 
相關問題