UITableView 删除表格 IOS 开发之UITableView 删除表格单元写法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

UITableView 删除表格 IOS 开发之UITableView 删除表格单元写法

  2021-03-29 我要评论
想了解IOS 开发之UITableView 删除表格单元写法的相关内容吗,在本文为您仔细讲解UITableView 删除表格的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:IOS,UITableView,删除表格,IOS,中UITableView,删除表格单元,下面大家一起来学习吧。

IOS 开发之UITableView 删除表格单元写法

实现代码:

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
      forRowAtIndexPath:(NSIndexPath *)indexPath {
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    NSDictionary *section = [data objectAtIndex:indexPath.section];
    if (section) {
      NSMutableArray *content = [section valueForKey:@"content"];
      if (content && indexPath.row < [content count]) {
        [content removeObjectAtIndex:indexPath.row];
      }
    }
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  } 
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
    NSDictionary *section = [data objectAtIndex:indexPath.section];
    if (section) {
      // Make a local reference to the editing view controller.
      EditingViewController *controller = self.editingViewController;
      NSMutableArray *content = [section valueForKey:@"content"];
      // A "nil" editingItem indicates the editor should create a new item.
      controller.editingItem = nil;
      // The group to which the new item should be added.
      controller.editingContent = content;
      controller.sectionName = [section valueForKey:@"name"];
      controller.editingTypes = [section valueForKey:@"types"];
      [self.navigationController pushViewController:controller animated:YES];
    }
  }
}


那一行是要自己添加的 然后把新加那一行的属性设置成UITableViewCellEditingStyleInsert就行了

如有疑问请留言或者到本站社区交流讨论,以上就是IOS 中UITableView 删除表格单元写法的实例,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们