表视图的编辑模式

来源:互联网 发布:centos安装zabbix3.0 编辑:程序博客网 时间:2024/06/05 09:55
表视图的编辑模式


表视图的编辑模式有三种,添加、删除和移动




表视图的编辑模式流程


核心代码


//新增、删除按钮事件
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{




//删除
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_data removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];




}
//新增
else if (editingStyle == UITableViewCellEditingStyleInsert) {
NSString *obj = [NSString stringWithFormat:@"我是新添加的"];
[_data insertObject:obj atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];




}
}
0 0
原创粉丝点击