在我重新排序 UITableViewCell 并滚动 tableView 后,单元格位于标题的顶部,而不是位于其下方。在我的 tableView 中,它的编辑属性总是设置为 YES,并且重新排序控件被拉伸以覆盖整个单元格。我试图sendSubviewToBack:
将单元格发送到后面并将bringSubviewToFront:
标题带到前面,但它没有用。
这是调整重新排序控件大小的代码:
- (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;
}
}
}
}
使用tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
单元格移动时和单元格移动后管理更新tableView:moveRowAtIndexPath:toIndexPath:
。
-(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++;
}
}