2013-04-27 89 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]; 
    }); 
} 

我希望這將幫助別人:)

相關問題