IOS 开发之UITableView 删除表格单元写法
程序员文章站
2023-12-18 21:33:22
ios 开发之uitableview 删除表格单元写法
实现代码:
- (void)tableview:(uitableview *)atableview co...
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 删除表格单元写法的实例,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!