Last week I explained how to reorder a cell from any point for a Scramble type game we had created. Another issue we faced with our Scramble game was the shadow behind each cell, which looked a tad weird. If you are facing the same issue, here is how you can correct it quite easily.
First download the sample project, which has everything set up. Go to the NoShadowTableView class, which is a subclass of UITableView. Here we will monitor all subviews of the table. First we need to know which subviews are used for shadows, so let’s make a dummy init method to set up a timer to print a list of subviews every second (a timer because the shadow is only visible when we’re reordering a cell).
Add the following code to NoShadowTableView.m
- (id) initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self != nil) { [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(printSubviews) userInfo:nil repeats:YES]; } return self; } - (void) printSubviews { NSLog(@"%@\n\n-------------", self.subviews); }
Run the project, you will see a print off of all subviews once every second. Hold down on a cell and read through the list, you will see a subview called UIShadowView (another private class not publicly available to developers). Delete the init and printSubviews methods, we dont need those now we know what the problem class is. To remove this class from our table we will override the didAddSubview: method, which is called after any subviews are added to a view.
Just like last week we will check the subview’s class type as a string. You may be tempted to remove the UIShadowView from the table when we find it, but to ensure retain counts are kept as intended, we will just set it to be hidden.
- (void) didAddSubview:(UIView *)subview { [super didAddSubview:subview]; // Hide any shadows if([[[subview class] description] isEqualToString:@"UIShadowView"]) [subview setHidden:YES]; }
That should be all, run the project and there will no longer be a shadow behind the cell being dragged. Hardly any code, but this technique can be used on many objects where unsupported customisation is required.


