开发者

How get rid of reorderControl while still using reorder?

Not long ago I asked about how to move reorderControl view close to the center of my custom cell, so this reorderControl break custom design. As I can't move this view and my cell always in editing mode - I just draw this reorderControl in right place of my cell background. But now I have two reorderControls ) one from my background in right place and one from iOS. If I set return value of - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath to NO, iOS reorderControl disappear but I can't reorder rows anymore.

How can I remove iOS reorderControl from screen and still be able to reorder my custom UITableViewCell?

ps cell.showsReorderControl=NO; is not wor开发者_C百科king


It's kind of a hack but the following does work

for(UIView* view in self.subviews)
    {
        if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
        {
            for(UIImageView* cellGrip in view.subviews)
            {
                if([cellGrip isKindOfClass:[UIImageView class]])
                    [cellGrip setImage:nil];
            }
        }
    }


The solution I got it work in iOS7 is to add another method to find reorder control. Since the tableview structure has changed in iOS7 It was a little bit hard to track UITableViewCellReorderControl. It is now in UITableViewCellScrollView.

The solution is like below

- (void)changeReorderControl:(UITableViewCell *)cell subviewCell:(UIView *)subviewCell
{
    if([[[subviewCell class] description] isEqualToString:@"UITableViewCellReorderControl"]) {

        [subviewCell.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

        UIImageView *imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hand"]];
        imageView.center = CGPointMake(subviewCell.frame.size.width/2 , subviewCell.frame.size.height/2);

        [subviewCell addSubview:imageView];
    }
}


- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    for(UIView* subviewCell in cell.subviews)
    {
            if([[[subviewCell class] description] isEqualToString:@"UITableViewCellScrollView"])                {
                for(UIView* subSubviewCell in subviewCell.subviews) {
                    [self changeReorderControl:cell subviewCell:subSubviewCell];
                }
            }
    }
}

Hope you will get the idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜