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++;
}
}