May 18, 2009

Swipe Delete From UITableView

You probably like to use swipe to delete elements from UITableView. Here you have a short example how to implement so in your iPhone applications.

On Swipe you receive the following message, you don't need to do anything in it:

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

When a user hits DELETE you can process it:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
// delete your data item here
// Animate the deletion from the table.
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];


Tuong Huy said...

Hi there, can i ask a question ?
I wanna custom the text on delete button (incase swipe-to-delete), do you know how to do that?
Thanks in advance

Anar Manafov said...

thx for passing by!

If we don't talk here about localizations, then I think there is no any official way to do what you want. But you could try an unofficial one.

You know in the UITableViewCell there is a property _removeControl. You could try to use.

something like it is done here, I guess:

Anyway, since this will change standard behavior of the control it may be problematic to pass AppStore review.

BTW, tell me whether it works at all.

Anar Manafov said...

sorry, in the previous comment the links were truncated.

Just go to

and search for

Tuong Huy said...

Thanks for the information Anar, it's really helpful and it WORK like charm.
Sorry because the late response cause i went out during last weekend. Just review those code that you provided, try to implements this morning and it work.
It's really nice and glad to meet you and i'm just coding for learning purpose so that i dont care much about AppStore's review.Beside i just change the label of Delete button incase swipe-to-delete, is that can be called change standard behavior of the control ? I didnt know where to find the list of AppStore review criteria.
Hope that i can keep in touch with you. If you're using skype then my skype id is huynvt83.
My name's Huy, from VietNam, sorry because of my bad English :)

Anar Manafov said...

Nice to see that it helped. ;)
Concerning AppStore review, I believe when I assigned to the iPhone developer program in the agreement it was mentioned that I must not used hidden API.
I think everything what starts with the underscore sign "_" in Cocoa is for Apple internal use only.
So, I am not really sure whether they accept this implementation or not. I just don't know. :(

I hope to see you next time on my blog ;) I don't have much time to post here, but I am going to update it time-to-time.

Tuong Huy said...

- Only work on iphone OS 2.2 or 2.2.1. I've upgrade my test device (iphone) to iphone OS 3.0 and the delete button has appear again without changing the label. So that i stuck here, searching for more information but nothing news till now.
- Also stuck with MapKit, searching for solution to develop with MapKit on iPhone OS 2.2 or 2.2.1 but i found out that MapKit framework does not include in iPhone SDK 2.2 (at least on iPhone simulator private framework)

Anonymous said...

As of iPhone OS 3 you can also use the following

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

oakleyses said...

louboutin pas cher, nike free, polo ralph lauren outlet online, louis vuitton, polo outlet, nike air max, longchamp pas cher, jordan shoes, ray ban sunglasses, gucci handbags, tiffany and co, jordan pas cher, cheap oakley sunglasses, louis vuitton outlet, oakley sunglasses, christian louboutin uk, nike free run, sac longchamp pas cher, nike air max, oakley sunglasses, longchamp outlet, prada outlet, kate spade outlet, longchamp outlet, louis vuitton, oakley sunglasses wholesale, polo ralph lauren, longchamp outlet, christian louboutin outlet, chanel handbags, louis vuitton outlet, tiffany jewelry, michael kors pas cher, replica watches, replica watches, ray ban sunglasses, ugg boots, burberry pas cher, tory burch outlet, nike roshe, oakley sunglasses, louis vuitton outlet, ray ban sunglasses, prada handbags, ugg boots, nike outlet, christian louboutin shoes, uggs on sale, christian louboutin

oakleyses said...

guess pas cher, north face, lululemon canada, michael kors, michael kors outlet online, true religion outlet, oakley pas cher, nike free uk, michael kors outlet, abercrombie and fitch uk, hollister uk, true religion outlet, hollister pas cher, ray ban pas cher, polo lacoste, north face uk, michael kors outlet online, coach outlet store online, ray ban uk, mulberry uk, burberry handbags, michael kors outlet, hogan outlet, nike blazer pas cher, nike air max, nike air max uk, true religion outlet, uggs outlet, coach outlet, nike air force, nike air max uk, sac hermes, uggs outlet, michael kors outlet, michael kors, michael kors outlet online, nike roshe run uk, vans pas cher, true religion jeans, replica handbags, ralph lauren uk, sac vanessa bruno, burberry outlet, nike tn, coach purses, new balance, michael kors outlet online, kate spade, timberland pas cher

oakleyses said...

hermes belt, hollister, lancel, abercrombie and fitch, chi flat iron, instyler, north face outlet, louboutin, asics running shoes, nfl jerseys, ferragamo shoes, new balance shoes, mont blanc pens, vans outlet, celine handbags, hollister clothing, mcm handbags, mac cosmetics, beats by dre, giuseppe zanotti outlet, converse outlet, nike air max, longchamp uk, oakley, reebok outlet, bottega veneta, nike air max, timberland boots, insanity workout, nike trainers uk, gucci, lululemon, baseball bats, soccer shoes, soccer jerseys, north face outlet, valentino shoes, wedding dresses, hollister, nike roshe run, vans, ray ban, babyliss, jimmy choo outlet, nike huaraches, p90x workout, ghd hair, ralph lauren, herve leger, iphone cases

oakleyses said...

ugg,uggs,uggs canada, barbour uk, moncler outlet, coach outlet, ugg,ugg australia,ugg italia, moncler, thomas sabo, canada goose, moncler outlet, links of london, canada goose outlet, juicy couture outlet, moncler uk, pandora jewelry, montre pas cher, marc jacobs, replica watches, louis vuitton, moncler, canada goose jackets, swarovski, pandora charms, canada goose outlet, toms shoes, moncler, swarovski crystal, doudoune moncler, louis vuitton, moncler, pandora jewelry, ugg, barbour, louis vuitton, hollister, canada goose outlet, karen millen uk, ugg pas cher, supra shoes, canada goose, juicy couture outlet, louis vuitton, wedding dresses, pandora uk, canada goose, ugg uk, canada goose uk, louis vuitton