gpt4 book ai didi

iphone - 无法在 tableviewcell ios 7 上显示删除按钮

转载 作者:可可西里 更新时间:2023-11-01 05:36:01 25 4
gpt4 key购买 nike

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

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

return UITableViewCellEditingStyleNone;
}

请帮助我找到解决方案,我对 iOS7 环境不太了解。谢谢!

最佳答案

谢谢大家的建议,这个方案可以解决,我做成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;
}
}
}

关于iphone - 无法在 tableviewcell ios 7 上显示删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19117161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com