UITableView that uses drag to delete?

Discussion in 'iOS Programming' started by dominsbeard, Oct 21, 2013.

  1. dominsbeard macrumors newbie

    Joined:
    Oct 8, 2013
    #1
    I'm trying to make a complete gesture based UITableView and have it so I can long press & drag to reorder. I also have it so you pull down to add a new cell. The last part I want is creating a "trash can" view at the bottom of the screen when the user can drag a cell down and drop it to delete. Similar to the messaging circles on the Facebook app that you can drag around and there is a delete view at the bottom. Except this is for tables.

    Does anyone know anything that does this with a UITableView? I think I know how to do it at an abstract level but I'd like an example to get me started.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    You probably need to ask more specific questions.

    UITableView has a way to reorder rows that is built-in and which many users will be familiar with. It might be best to use that.

    I guess there's also a way to delete a row by swiping.

    OK, assuming you want to do this all yourself I might take this approach. When the user starts a drag I would generate an image of the row. Then add the image to an image view, set the image to be partly transparent, and let the user drag the image view. There's some very old sample code from Apple called MoveMe that shows how to drag a view around the screen.

    Then it's up to you to manage what happens when the image goes over the trashcan and then when the user drops the image over the trashcan. (Animate the trashcan, remove the row from the table. etc.)

    It's conceivable that you could do something clever with the tableview to allow reordering in response to the user moving this image view. You could insert a blank row to indicate where the row is supposed to drop. You could move the blank row up or down as the user moves the image view. Then delete the row and reinsert it in the new position. I think you'll have to do some experimentation to get this right though.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    UITableView has built-in support for row deletion. Is there a reason you want your users to do it differently than what they would be used to?
     

Share This Page