Is it possible to both edit and delete a table row after you enter editing mode on the TableView? I have figured out how to do the delete one seperately. Using the standard editing button and then delete.
But I would like it to be so that I can press the edit button, and it gives me the option per row to delete or edit. Like the way it works in the Clock > Alarm on your iphone. Both options are activated through the edit button, but I don't quite see how.
I have looked on google, and stackoverflow but I cannot find a solution to this. If there are any examples out there or tutorials that you know of (and I did not find) please do share them.
You could try to change your didSelectRowAtIndexPath method. Do a check if the [self.table isEditing] and if it is editing you change what your didSelectRowAtIndexPath method does.
Related
I ran into the problem that I need to invoke swipes for all cells except the last one by calling SetEdit. That is, I click on the Edit button, a number of cells are shifted to the right and their actions are shown. They should be static in this position and you can, for example, click on deleting or editing a cell. Is this even possible?
I have already tried a lot of things, but I could not even achieve the result.
Thanks in advance !
I'll talk about UITableViewRowAction which is availeble from iOS 8. I need to made 2 things
When user swipes left show 2 UITableViewRowActions (delete and favorite)
This one Im already made buy adding 2 UITableViewRowActions in
tableView: editActionsForRowAtIndexPath:
When the user taps to "delete" row action which is already shows - I need to show one more row action (confirmation)
I have no mind how to add row action from row action handler...
Sorry for bad English.
Thanks.
I think this is impossible. Adding a row action dynamically requires reloading the tableview, and this would require the user to swipe to the left again. You then would need to set a property (waitingForConfirmation = true), and then add the rowAction in editActionsForRowAtIndexPath if the property is set to true. This will not be user friendly at all, and I do not view it as a valid solution.
The best solution would probably be to show a UIAlertController and then ask the user to confirm, and run the required code afterwards by adding the code in the completion handler of the button.
I am hoping there is a way to programmatically display the swipe left edittask list for a given cell. I tried everything I could think of to get it to display but nothing seems to work.
I am able to show them with a swipe left without issue but I need the ability to show them programmatically.
How to accomplish this?
Try setting editing on the cell. According to this from Apple, it should display the edit actions.
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.
So I stumbled upon a rather inconvenient 'feature' of the iOS SDK last night, and I wanted to share my finding and solution with you guys. Also to get input, should there be a better solution.
Scenario
I had a table view set up with two sections, on for favorite items another for all other items. Tapping a row in the table view would toggle whether the item is marked as favorite; tapping a row in the favorite items section, would remove it from favorites, while tapping a row in the all other items section would add this item to the favorites.
When the state of favorite is toggled, I use moveRowAtIndexPath:toIndexPath: to do a nice little animation and move the row from favorites section to all others section.
Problem
So, the problem occured because, not only should the user be able to toggle favorite state, also all of the items in the favorites section should be rearrangeable. Thus I wanted to display a rearrange control in each row of the favorite items section.
However, a cell isn't redrawn when invoking moveRowAtIndexPath:toIndexPath: and fromIndexPath and toIndexPath are both in the visible area. This means that the rearrange control is not displayed when adding a new row to the favorite items section.
Solution
After looking through page-after-page in the documentation, thread on StackOverflow and trying out various stuff, I finally found a solution.
Immediately after calling moveRowAtIndexPath:toIndexPath: I also invoke the following lines:
[cell setEditing:NO]
[cell setEditing:YES]
Which would cause that one cell to understand that it's restriction for rearrangement has changed, thus show/hide the rearrange control appropriately.
I find this solution to be very hacky, so I'd be happy to hear about better solutions. But at least, a solution is out here now, for other people to enjoy.