无法在tableviewcell ios 7上显示删除按钮 [英] Cannot show Delete button on tableviewcell ios 7

查看:138
本文介绍了无法在tableviewcell ios 7上显示删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UITableviewcellEditingstyleDelete 显示用户点击它以显示删除按钮的按钮(这与您在电子邮件应用中看到的方式相同,当用户点击编辑然后点击在按钮上显示删除按钮)。它在ios6中工作正常但是当我在具有ios 7的设备上构建我的应用程序时,删除按钮消失了,但当你点击删除按钮的区域时它也可以删除。问题是用户无法看到删除按钮(OS提供的红色按钮)。
我的代码是:

I used UITableviewcellEditingstyleDelete to show button for user click on it to show delete button (it's the same way you can see on email app, when user click edit and then click on button to show the delete button). It's work fine in ios6 but when I build my app on device which have ios 7, the delete button is disappear, but when you tap in the delete button's area it's also can delete. The prolem is user cannot see the delete button (The button which have red color provide by OS). My code is:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Detemine if it's in editing mode
    if (self.editing)
    {
       return UITableViewCellEditingStyleDelete;
    }

   return UITableViewCellEditingStyleNone;
}

请帮我找到解决方案,我对iOS7了解不多enviroment.Thanks!

please help me to find the solution, I'm not know much with iOS7 enviroment.Thanks!

推荐答案

感谢大家的建议,这个解决方案可以解决它,我把它变成自定义单元格

Thanks all for your advice, and this solution can solved it, I make it into custom cell

 UIImageView* backgroundImage;

//Variable for animation delete button
// Keep the ContactView in normal state
BOOL bFirstEditingCell;
BOOL bShownRedMinus;
BOOL bShownDeleteButton;
CGRect frameOfContactViewInNormal;
CGPoint centerOfCellInNormal;
UITableViewCellAccessoryType accessoryTypeInNormal;

//

 - (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super initWithCoder:decoder])
    {
        super.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row_gradient" ]];
        self.backgroundView = backgroundImage;
        bShownDeleteButton = false;
        bShownRedMinus = false;
        bFirstEditingCell = true;
        accessoryTypeInNormal = UITableViewCellAccessoryNone;
    }
    return self;
}


- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
if (!isOS7()) {
    return;
}

for (UIView *subview in self.subviews) {
    //Keep normal value of contact view and cell
    if (bFirstEditingCell   ) {
        frameOfContactViewInNormal = self->contactView.frame;
        frameOfContactViewInNormal.size.width = kContactViewWidth;
        centerOfCellInNormal = subview.center;
        bFirstEditingCell = false;
    }

    if (state == UITableViewCellStateDefaultMask) {
        self.backgroundView = backgroundImage;
        subview.center = centerOfCellInNormal;
        //Set for position of speed dial image
        CGRect f = frameOfContactViewInNormal;
        if (bShownRedMinus) {
            f.size.width -= kRedMinusButtonWidth;
        }
        self->contactView.frame = f;
        bShownDeleteButton = false;
        self.accessoryType = accessoryTypeInNormal;
    }
    else if (state == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        float sectionIndexWidth = 0.0;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            sectionIndexWidth = 30.0;
        }
        else {
            sectionIndexWidth = 15.0;
        }
        CGPoint center = centerOfCellInNormal;
        subview.center = CGPointMake(center.x - sectionIndexWidth, center.y);
        self.backgroundView = nil;

        //Set width of contact name
        UIView* view = [subview.subviews objectAtIndex: 0];
        CGRect f = view.frame;
        f.origin.x = (kDeleteButtonWidth + sectionIndexWidth);
        view.frame = f;
        f = frameOfContactViewInNormal;
        f.size.width = self.frame.size.width - (kDeleteButtonWidth + sectionIndexWidth);
        self->contactView.frame = f;
        bShownDeleteButton = true;
        bShownRedMinus = false;
        accessoryTypeInNormal = self.accessoryType;
        self.accessoryType = UITableViewCellAccessoryNone;
    }
    else if (state == UITableViewCellStateShowingEditControlMask) {
        CGRect f = frameOfContactViewInNormal;
        f.size.width -= 5;
        self->contactView.frame = f;
        bShownRedMinus = true;
    }
    else if (state == 3) { //State for clicking red minus button
        CGRect f = frameOfContactViewInNormal;
        f.size.width += kRedMinusButtonWidth;
        self->contactView.frame = f;

        self.backgroundView = nil;
    }
}
}

这篇关于无法在tableviewcell ios 7上显示删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆