IOS 开发之UITableView 删除表格单元写法
IOS开发之UITableView删除表格单元写法
实现代码:
-(void)tableView:(UITableView*)aTableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath*)indexPath{
if(editingStyle==UITableViewCellEditingStyleDelete){
NSDictionary*section=[dataobjectAtIndex:indexPath.section];
if(section){
NSMutableArray*content=[sectionvalueForKey:@"content"];
if(content&&indexPath.row<[contentcount]){
[contentremoveObjectAtIndex:indexPath.row];
}
}
[tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade];
}
elseif(editingStyle==UITableViewCellEditingStyleInsert){
NSDictionary*section=[dataobjectAtIndex:indexPath.section];
if(section){
//Makealocalreferencetotheeditingviewcontroller.
EditingViewController*controller=self.editingViewController;
NSMutableArray*content=[sectionvalueForKey:@"content"];
//A"nil"editingItemindicatestheeditorshouldcreateanewitem.
controller.editingItem=nil;
//Thegrouptowhichthenewitemshouldbeadded.
controller.editingContent=content;
controller.sectionName=[sectionvalueForKey:@"name"];
controller.editingTypes=[sectionvalueForKey:@"types"];
[self.navigationControllerpushViewController:controlleranimated:YES];
}
}
}
那一行是要自己添加的然后把新加那一行的属性设置成UITableViewCellEditingStyleInsert就行了
如有疑问请留言或者到本站社区交流讨论,以上就是IOS中UITableView删除表格单元写法的实例,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!