只需要实现三个代理方法就可以了
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _BarCodeTableView) {
return @"删除";
}
return @"";
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCellEditingStyle result = UITableViewCellEditingStyleNone;//默认没有编辑风格
if ([tableView isEqual:_BarCodeTableView]) {
result = UITableViewCellEditingStyleDelete;//设置编辑风格为删除风格
}
return result;
}
//这里就是点击删除执行的方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == _BarCodeTableView) {
}
}
本文介绍如何在iOS应用中使用代理方法实现UITableView的删除功能。通过三个关键的代理方法,可以轻松地为表格视图添加删除按钮,并定义点击删除按钮后的行为。
3万+

被折叠的 条评论
为什么被折叠?



