讲解iOS开发中UITableView列表设计的基本要点

2020-01-14 19:26:15于海丽

}
③设置行可移动,并完成移动行方法,改变数据源

 

// 移动行操作-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{// 这里其实就是数组中两个变量交换位置的过程 id object = [self.dataArray objectAtIndex:fromIndexPath.row];
     
    [self.dataArray removeObjectAtIndex:fromIndexPath.row];
     
    [self.dataArray insertObject:object atIndex:toIndexPath.row];
}


5、批量删除行

 

①即完成可以选择多个行之后批量删除,如图

讲解iOS开发中UITableView列表设计的基本要点讲解iOS开发中UITableView列表设计的基本要点

②在ViewDidLoad中添加代码

self.navigationItem.rightBarButtonItem = self.editBarButtonItem;// 在右导航栏中添加编辑按钮
③现在需要达到,点击编辑按钮在右上角出现取消按钮,左上角出现删除按钮。并在选择时,能出现删除行的数量,修改updateBarButtons方法,并添加一个方法来根据条件修改删除按钮的标题

复制代码
// 更新导航栏按钮
-(void) updateBarButtons
{
    // 如果是允许多选的状态,即进入批量删除模式
    if (self.tableView.allowsSelectionDuringEditing == YES) {