这篇文章主要介绍了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实现监听音量的变化 2023-03-30
- 详解flutter engine 那些没被释放的东西 2022-12-04
- Android实现轮询的三种方式 2023-02-17
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- iOS 对当前webView进行截屏的方法 2023-03-01
- Flutter实现底部和顶部导航栏 2022-08-31
- Android studio实现动态背景页面 2023-05-23
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
