3
votes

I've got a uitableview that I've rotated 180 degrees but whose cells I've rotated back -180 degrees. The effect is that I am loading my data from the bottom of the table view. This works great. The problem comes when I try to reorder the cells. If I try to drag a cell its movement is inverted and jumps immediately to the top/bottom of the table view, depending on which direction I was dragging.

The easiest way to see this is by starting a new project using the master detail template with core data. In the OIMasterViewConroller.m file place

CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159);
self.tableView.transform = transform;

in the viewDidLoad method, and place

CGAffineTransform transform = CGAffineTransformMakeRotation(-3.14159);
cell.transform = transform;

in the configureCell method. Finally, change the canMoveRowAtIndexPath to return YES and implement a blank

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {

}

Run the project and add a few items to the tableview with the + button. Then Click on the edit button and try to reorder.

I believe the problem lies with the cell since removing the rotation on the cell will stop this strange behavior, even though the table is upside down.

I thought about just rotating the text inside the cell, but then the delete buttons are upside down, as well as on the wrong side.

1

1 Answers

4
votes

So, I ended up subclassing both the tableview and the cell used in the table view. Here is some of what I've done:

In the tableview subclass I overload the layoutsubviews:

- (void)layoutSubviews
{
    [super layoutSubviews];

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UIShadowView"]) {
            subview.hidden = YES;
        }
    }
}

This removes the drop shadow. If you don't the shadow shows at the top of the tableviewcells when they are being reordered.

For the tableviewcell subclass I changed its layoutSubviews like this:

- (void)layoutSubviews
{
    [super layoutSubviews];

      for (UIView *subview in self.subviews) {        
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 0;
            subview.frame = newFrame;
            subview.transform = CGAffineTransformMakeRotation(-M_PI);
        }
        else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 320-newFrame.size.width;
            subview.frame = newFrame;
            subview.transform = CGAffineTransformMakeRotation(-M_PI);
        }
        else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellReorderControl"]) {
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 0;
            subview.frame = newFrame;
        }else if([NSStringFromClass([subview class]) isEqualToString:@"UIButton"]) {
            CGRect newFrame = subview.frame;
            newFrame.origin.x = 0;
            subview.frame = newFrame;
            subview.transform = CGAffineTransformMakeRotation(-M_PI);
        }else{
            subview.transform = CGAffineTransformMakeRotation(-M_PI);
        }
    }  
}

This rotates and moves all the delete buttons/indicators ect. The important thing to note is that we DO NOT rotate the UITableViewCellReorderControll. Rotating this subview is what makes the reordering messed up.