gpt4 book ai didi

iphone - 如何只删除一个部分中的行

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

我创建了一个包含 2 个部分的表格,我希望应用程序在按下编辑按钮时仅在第一部分而不是第二部分显示删除按钮,我编写了以下代码

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
Book_own *temp= (Book_own *)[self.books objectAtIndex:indexPath.row];

if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source

[books removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
}

但是当我按下“编辑”按钮时,它在两个部分都显示了删除按钮,我怎样才能防止这种情况发生并只在第一部分进行删除???

最佳答案

试试这个...

-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

if(indexPath.section == yourVariable) return UITableViewCellEditingStyleDelete;

else return UITableViewCellEditingStyleNone;

}

关于iphone - 如何只删除一个部分中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10664936/

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