开发者

How can I delete a custom UITableViewCell without using commitEditingStyle?

I have a custom UITableViewCell that has a delete button on it at all times.

When the delete button is pressed, the current design is to flash an alert confirming the delete with Yes/No.

So far, all of this is working.

The problem is, actually pressing 'Yes' does not update the UITableVie开发者_运维知识库w. It will delete the data from model, but the row will still be there.

[table beginUpdates];

//modify model code goes here

[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

[table endUpdates];

[table reloadData];

So the above code will update the model, but not the view. I can tell that the model is being updated, because:

(A) attempting to delete the same cell again results in a crash

(B) moving to another screen and coming back results in the cell being deleted

I would like the result of (B) without having to leave the screen.

I would not like to use commitEditingSyle unless there is way to do this without the user knowing they are editing. I certainly do not want the standard delete button or the swipe to delete functionality.


As i understand, you delete your model.
In situation B, the view will appear again, which reloads your data and builds up the UITableView.

When your remove your model, do you remove it from the collection?
I think not. Your application will rebuild the view with the same data (your model is not removed from memory when you reload your data).

Your flow should be as following:

View loads/appears
   Load Data
   Load table

Model Delete Action
   Delete Data
   (Re)Load Data
   Load table

I'm not sure, but i think you forget to reload the data.

Another tip:
You should use the slide to delete. It is the standard defined in the Human Interface Guidelines (HIG)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜