您的位置:首页 > 产品设计 > UI/UE

UITableView划动删除的实现

2015-02-03 19:52 423 查看
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

return YES;

}

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

if (editingStyle == UITableViewCellEditingStyleDelete) {

[dataArray removeObjectAtIndex:indexPath.row];

// Delete the row from the data source.

[testTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

else if (editingStyle == UITableViewCellEditingStyleInsert) {

// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.

}

}

以上代码实现tableview中cell滑动删除

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

{

return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;

}

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

if (rightButton.title== @"确定") {

[deleteDic setObject:indexPath forKey:[dataArray objectAtIndex:indexPath.row]];

}

else {

}

}

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

if (rightButton.title == @"确定") {

[deleteDic removeObjectForKey:[dataArray objectAtIndex:indexPath.row]];

}

}

[dataArray removeObjectsInArray:[deleteDic allKeys]];

[self.tableview deleteRowsAtIndexPaths:[NSArray arrayWithArray:[deleteDic allValues]] withRowAnimation:UITableViewRowAnimationFade];

[deleteDic removeAllObjects];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: