【发布时间】:2014-01-15 16:14:53
【问题描述】:
我有几个 UITableViewCell 子类,它们覆盖了 - (void)setEditing:(BOOL)editing animated:(BOOL)animated 方法。在我的实现中,当单元格被滑动时,我有动画来显示和隐藏自定义视图。在 iOS 6 上,这可以完美运行。我的自定义视图是动画的,并且没有显示默认的删除按钮。然而,在 iOS 7 上,我得到了我的自定义视图和动画以及默认的删除按钮。我正在努力寻找一种方法来使用我被覆盖的setEditing:animated:,而无需获得系统删除按钮。
在我的 UITableViewCell 子类中,我已经像这样覆盖了setEditing:animated::
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (editing) {
CGFloat buttonWidth = _editButton.frame.size.width;
[UIView animateWithDuration:0.3
delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations: ^{
[_shareButtonXConst setConstant:buttonWidth * -3.0];
[self layoutIfNeeded];
}
completion:nil];
} else {
[UIView animateWithDuration:0.3
delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations: ^{
[_shareButtonXConst setConstant:0.0];
[self layoutIfNeeded];
}
completion:nil];
}
}
在我的 UIViewController 我有:
- (void)loadView
{
// ...
UITableView *tableView = [[UITableView alloc] init];
_tableView = tableView;
[_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[_tableView setBackgroundColor:[UIColor clearColor]];
[_tableView setRowHeight:80.0];
[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[_tableView setDelegate:self];
[_tableView setDataSource:self];
// ...
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
我已经对此进行了相当多的修改,并且在我滑动时无法阻止删除按钮出现。有没有其他人遇到过这个问题?谢谢!
【问题讨论】: