2013-04-27 57 views
1

我重新排序UITableViewCell并滚动tableView后,单元格将在标题顶部而不是在其下方。在我的tableView中,其编辑属性始终设置为YES,并且重新排序控件被拉伸以覆盖整个单元格。我试过sendSubviewToBack:发送信元到后面,bringSubviewToFront:将信头放到前面,但它不起作用。UITableViewCells重新排序后滚动

下面是调整的重排序控件的代码:使用tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:而细胞移动,并tableView:moveRowAtIndexPath:toIndexPath:一旦电池已被移动

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    JRBTask *task = [[[JRBTaskStore sharedStore] taskArrayWithIndex: indexPath] objectAtIndex: [indexPath row]]; 

    if (![task reorderControlIsResized]) { 
     // Grip customization code goes in here... 
     for(UIView* view in cell.subviews) 
     { 
      if ([[[view class] description] isEqualToString:@"UITableViewCellEditControl"]) 
       [view removeFromSuperview]; 
      if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"]) 
      { 
       UIView* resizedGripView = [[UIView alloc] init]; 

       // Use initial frame so it's resizing from its initial 
       // position each time, not from its current position 
       if (!initialFrame.size.height) 
        [resizedGripView setFrame: CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; 
       else 
        [resizedGripView setFrame: initialFrame]; 

       if (!initialFrame.size.height) 
        [self setInitialFrame: resizedGripView.frame]; 

       [resizedGripView addSubview:view]; 
       [cell addSubview:resizedGripView]; 

       CGSize sizeDifference = CGSizeMake(initialFrame.size.width - view.frame.size.width, initialFrame.size.height - view.frame.size.height); 
       CGSize transformRatio = CGSizeMake(initialFrame.size.width/view.frame.size.width, initialFrame.size.height/view.frame.size.height); 

       // Original transform 
       CGAffineTransform transform = CGAffineTransformIdentity; 

       // Scale custom view so grip will fill entire cell 
       transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height); 

       transform = CGAffineTransformTranslate(transform, -139, -sizeDifference.height/2.0); 

       [resizedGripView setTransform: transform]; 

       for(UIImageView* cellGrip in view.subviews) 
       { 
        if([cellGrip isKindOfClass:[UIImageView class]]) 
         [cellGrip setImage:nil]; 
       } 
       reorderNeedsAdjusted = NO; 

      } 
     } 
    } 
} 

的更新管理。

-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath 
{  
    return proposedDestinationIndexPath; 
} 

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{ 
    [[JRBTaskStore sharedStore] moveTaskFromIndex: sourceIndexPath toIndex: destinationIndexPath]; 

    // Update number of rows in section if the section is different 
    if ([sourceIndexPath section] != [destinationIndexPath section]) { 
     // Subtract from source section 
     if ([sourceIndexPath section] == 0) 
      numberOfRowsInToday--; 
     else if ([sourceIndexPath section] == 1) 
      numberOfRowsInTomorrow--; 
     else if ([sourceIndexPath section] == 2) 
      numberOfRowsInUpcoming--; 
     else 
      numberOfRowsInSomeday--; 

     // Add to destination section 
     if ([destinationIndexPath section] == 0) 
      numberOfRowsInToday++; 
     else if ([destinationIndexPath section] == 1) 
      numberOfRowsInTomorrow++; 
     else if ([destinationIndexPath section] == 2) 
      numberOfRowsInUpcoming++; 
     else 
      numberOfRowsInSomeday++; 
    } 
} 

Issue

+0

请添加您使用重新排序,并刷新实现代码如下代码 – Stephen 2013-04-27 03:54:37

+0

试试这个[self.tbl setBounces:NO]; – iphonic 2013-04-27 05:47:49

+0

如何管理更新,告诉表视图移动行,并在编辑“会话”完成时告诉它? – Wain 2013-04-27 08:35:07

回答

0

我知道这是不是最好的答案。但是,它适用于我。 IOS7后解决了这个问题。

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{ 
    UITableViewCell * movedCell = [tableView cellForRowAtIndexPath:sourceIndexPath]; 
    double delayInSeconds = 0.3; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [tableView sendSubviewToBack:movedCell]; 
    }); 
} 

我希望这将帮助别人:)