ios - UITableView 删除按钮没有出现

标签 ios uitableview ipad editing

当我按下编辑按钮时,我会在项目左侧看到圆形删除图标。当我按下单元格中的删除图标时,它会“转动”但删除按钮不会显示,因此我的 commitEditingStyle 永远不会被调用,因为我没有要按下的删除按钮。

只是为了好玩...我将单元格更改为 Insert 我得到加号图标...我按下它并调用 commitEditingStyle。

我不明白为什么我没有看到删除按钮。

我有一个在弹出窗口中显示的 UIViewController。我正在添加一个 UITableView 以这样......

audioTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 303)];
audioTable.delegate = self;
audioTable.dataSource = self;
[self.view addSubview:audioTable];

我正在使用一个带有两个标签的自定义单元格来显示文本。

这是自定义单元格 initWithFrame...

primaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,8, 275, 25)];
primaryLabel.font = [UIFont systemFontOfSize:14];

secondaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(25 ,28, 275, 25)];
secondaryLabel.font = [UIFont systemFontOfSize:12];

[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];

[self.contentView sendSubviewToBack:primaryLabel];
[self.contentView sendSubviewToBack:secondaryLabel];

我在连接到编辑调用的 View Controller 的工具栏中有一个删除按钮。这是我在编辑调用中所做的,它被调用得很好,因为我在单元格中得到了删除符号...

if([self.audioTable isEditing]) {
    [button setTitle:@"Edit"];
    [super setEditing:NO animated:NO];
    [self.audioTable setEditing:NO animated:YES];
} else {
    [button setTitle:@"Done"];
    [super setEditing:YES animated:NO];
    [self.audioTable setEditing:YES animated:YES];
}

我已经实现了以下...

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
     return UITableViewCellEditingStyleDelete;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    //i don't think i need to implement this really
    return YES;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //do delete stuff
    }
}

就像我说的,一切正常,按下按钮,一切正常……只是没有删除按钮。

最佳答案

我不得不使用不同的机制来解决这个问题。我做了一个测试,当我使用 UITableViewController 时它工作正常。当我将 UITableView 添加到 UIViewController 时,实现与 UITableViewController 相同的功能,但它不起作用。我不知道我错过了什么,但是使用 UIViewController 而不是 UITableViewController 导致删除按钮不出现。

关于ios - UITableView 删除按钮没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11956673/

相关文章:

iOS 8 SDK : modal UIWebView and camera/image picker

ios - 从后台返回后,AudioKit SynthOne崩溃

ios - UITableView 中的几个单元格

javascript - HTML5 : Video on the iPad - Custom Zoom Control

ios - iPad 显示从弹出窗口中选择的图片

objective-c - 如何使用pdf文件缩放webView

ios - 如何使用 Google Maps iOS SDK 获取地址组件的完整列表

iphone - 通过NSNotification设置时,UIImageView.image需要花费几秒钟的时间才能显示

ios - 如何根据图像大小设置高度的单元格

ios - 以编程方式将 UITableViewCell 添加到 UITableView