UITableView loses selection after swipe - uitableview

I have a problem with the UITableView selection. If I swipe to show the Delete button, and then I tap somewhere else to cancel it, I loses the current selection.
How can I retain my selection by the Table even having done that, or at least know if the Delete button is being dismissed (so that I can manually re-select it)?

That is the default swipe to delete behaviour. There isn't any clean ways to retain the selection after you scroll.
It sounds like what you're trying to do is just to remember a cell selection? In that case, you will need to override the swipe gesture and add your own method. You can store this information any way you like.
As an example, you can check out this project that shows how to handle selections.

Related

Turn off delete confirmation in table view cell after tap on the deletion control

In my tableView I use editing mode for deleting and inserting rows. When I tap on delete, the "delete" button appears on the right of the cell. I want to delete the cell immediately without confirmation.
Is there any way to turn off this delete confirmation after tapping on deletion control?
I want to remove this delete confirmation button.
Unfortunately I didn't find any good native solution for this problem. I solved this problem by custom UIButton which I placed in my custom uitableViewcell, which triggers deletion of the row.

Swift-UITableView show swiped cells in editing style

I am working on one tableview and I would like to make animation with defaultly enabled editing style, where all cells would be swiped to left and I would be able to see delete button in all cells and for example after 1 second, I want to go to default state of tableview. It's due to informing user, that some swipe feature is there available.
Has anyone any idea how to implement it? Thanks a lot.

How to disable the selection on UITableViewCell's accessory view only?

My UITableViewCell has an accessory view of UIButton on the right edge of the cell. However, the button might not be available to an user and thus I shall disable it via self.myButton.enabled = false.
While this makes the cell selection work as usual however, now the selection also reacts to the tap on the button. In other words, while the button is disabled and the user still taps on the button, the tap is now responding to the didSelectRowAtIndexPath: method.
This is not what I want, since it might confuse my users at times. So I want to implement it as follows:
When the button is available, tapping the cell and tapping the button execute different methods respectively (which I implemented and worked).
When the button is unavailable, tapping the cell works only on the part of where the button is not located.
Is it possible to set the functionality here?

How to enable both swipe to delete and a delete button made in edit mode in UITableView

By default edit mode is on, that's why swipe on cell, it will delete like this, and when click on edit following method use to delete the data
Right now it works correctly but either one of them is going to use. I want to use both method for delete cell.
Please help me to find some code snippet or tutorial link
The natural iOS behaviour for Edit mode in a UITableView is just showing the '-' button for deletion, thats the way I recommend you to use, because of the users are use to deleting on that way.
With this library, you can assign custom buttons and actions for both Swipe directions. Maybe with it you can achieve what you want.
https://github.com/MortimerGoro/MGSwipeTableCell
I would try to add a custom right UIBarButton with a custom action, and after it get pressed, you can try to force swiping the cell to both directions, and showing the buttons you want.

How can you get the delete confirmation button to show up on UITableViewCell if you tap the cell?

I have implemented a UITableView to allow the standard delete button to show up on the far right of a cell when the user swips over it. I have a use case where I want to show this same delete button when a user taps on a cell.
I am able to handle the tap in the delegate method didSelectRowAtIndexPath, but I can not figure out how to show the delete button. I have found a lot of references on how to show the delete icon on the left of the cell, but not for the delete button that shows up when you normally swipe. Is there a way to do this, or do I need to create my own custom button?
I'm afraid there is no way to do this. You could simulate touches making a swipe, but that'd involve using private APIs. You will have to manually create your own delete button.

Resources