gpt4 book ai didi

ios - UITableView 删除按钮没有出现

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:51 25 4
gpt4 key购买 nike

当我按下编辑按钮时,我会在项目左侧看到圆形删除图标。当我按下单元格中的删除图标时,它会“转动”但删除按钮不会显示,因此我的 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/

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