ios - 当显示删除确认按钮时,UITableViewCell.showingDeleteConfirmation 给出 NO

标签 ios objective-c uitableview

我在表格 View 单元格上滑动以显示删除确认按钮。但是,一旦我抬起手指,即使按钮仍然存在,showingDeleteConfirmation 也会给出“否”。 (当按钮出现时,我的意思是,在我抬起手指之前,它确实会给出"is"。)我是否遗漏了某些东西,或者这是 iOS 中的一个真正的错误?

以下是我的测试代码。 (复制粘贴到单 View 项目的ViewController.m中并在模拟器中运行,shift+command+M触发NSLog。)

#import "ViewController.h"


@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@end


@implementation ViewController {
    UITableViewCell *_myCell;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
    myTableView.dataSource = self;
    myTableView.delegate = self;
    [self.view addSubview:myTableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    _myCell = [[UITableViewCell alloc] init];
    _myCell.contentView.backgroundColor = [UIColor greenColor];
    return _myCell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

    NSLog(@"_myCell.showingDeleteConfirmation = %@", _myCell.showingDeleteConfirmation ? @"YES" : @"NO");
}

@end

最佳答案

根据文档:

Returns whether the cell is currently showing the delete-confirmation button. (read-only)

...

When users tap the deletion control (the red circle to the left of the cell), the cell displays a "Delete" button on the right side of the cell

所以首先你需要使网格可编辑

[myTableView setEditing:YES];

然后用户点击圆圈进行删除(在此模式下他们无法向左滑动),瞧:

_myCell.showingDeleteConfirmation = YES

虽然您可以按照问题中所述使用它,但他们不 promise 。

关于ios - 当显示删除确认按钮时,UITableViewCell.showingDeleteConfirmation 给出 NO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21969527/

相关文章:

ios - 如何使用持续时间为单个 UICollectionView 单元格设置动画

ios - 在 iOS 应用程序中捕获签名

objective-c - 如何检测在 View 上添加了 UIGesture。( objective-c )

ios - 在 iOS 应用程序中的什么位置放置设备特定值?

iphone - 如何默认选择 UITableViewCell?

ios - swift 属性的未知类型名称

使用 Azure 网站和类似网站托管 iOS 企业应用程序

objective-c - 为什么 Apple 在其类中使用 "flags"结构体?

ios - 如何segue UIImage?

arrays - SWIFT 单元格填充