uitableview 的可编辑性小结

浪子不回头ぞ 提交于 2020-02-29 06:03:33

在让tableview可编辑时,添加实现下面3个delegate方法:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

    return YES;

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewCellEditingStyleDelete;

}

// 添加这个方法后可以滑动cell,显示delete,  ps: editingStyleForRowAtIndexPath 为 UITableViewCellEditingStyleInsert 的时候滑动无效, 需要自行添加[tbView_roster setEditing:YES animated:YES]; 例如下面在 didSelectRowAtIndexPath 中添加 setEditing:animated:

- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

        // do sth...

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tbView_roster setEditing:YES animated:YES];

}


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!