这篇文章主要介绍了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 删除表格单元写法的实例,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程基础网
本文标题为:IOS 开发之UITableView 删除表格单元写法
基础教程推荐
猜你喜欢
- Android zxing如何识别反转二维码详解 2022-11-08
- iOS的音频文件的格式转换示例 2023-06-11
- Kotlin的枚举与异常示例详解 2022-12-07
- iOS统计项目的代码总行数 2022-11-01
- 使用Android Studio创建OpenCV4.1.0 项目的步骤 2023-02-26
- Android自定义view实现圆形进度条效果 2023-05-26
- 以代码实例总结iOS应用开发中数据的存储方式 2022-11-20
- iOS微信分享后关闭发送成功提示并返回应用 2023-01-03
- Android自定义悬浮按钮效果 2023-04-22
- iOS对数组进行排序的实例代码 2023-03-16
