views:

83

answers:

1

like build in apple notes app, after you swipe to delete the selected row, it will select the nearest available row automatically.

The logic should be:

if row count > 0 then if deleted_row == last row then
select deleted_row_index-1 row
else
select deleted_row_index+1 row
end
end

i have try to implement the above logic in the commitEditingStyle event, but the selection fail.
the selectRowAtIndexPath logic just don't work in this event, if i apply it in a button, it works.

any idea?

A: 

When you delete a row, you should have its indexPath. Then you call the method

(void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

For indexPath you can set the new indexPath, by increasing or decreasing the indexPath.row by 1.

scrollPosition sets whether the tableView scrolls up or down, and animated should be clear.

After all, you manually select that UITableViewCell.

[cell setSelected:YES];
burki