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

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?

Related

iOS UITableView Editing with Accessibility

I am working on an app that supports Apple's voice over accessibility option.
I have a screen with a tableview that has an editing state for the tableview in which the user can swipe and/or tap the red delete button at the beginning of the table view cell to delete the cell.
All of the functionality works fine with voice over turned off, but when I turn voice over on, the delete button is not in the swipe order, nor can you tap it.
Is there something special I need to do to enable the user to tap/swipe the cell while voice over is enabled?
I ended up figuring this out.
Apparently the way the voice over works with editing commands on table view's is that once the cell is highlighted, you can swipe up and down to go through the custom action commands. Once the command you want is spoken, you can double tap the screen to execute the command.
It's a little confusing since the delete button on the cell is never highlighted, which was what was throwing me off.

How to prevent disclosure button being triggered on a UITableViewCell when swiping left

This seems like a simple enough problem but I can't seem to find a solution.
I have a table view that has cells with the disclosure button. I'm using accessoryButtonTappedForRowWithIndexPath to trigger the click on the button so that it takes the user to an info page.
I also have the swipe left to delete action set up on the cell.
The problem is, when the user swipes left, but while doing so touches the disclosure button, both actions occur (meaning accessoryButtonTappedForRowWithIndexPath gets fired, but also the swipe left happens).
Is there any way to prevent this? I would like that when the swipe happens, only "swipe left to delete" occurs and the info page does not fire (which should only fire upon a click).
I'll attempt to explain what I think was going on. The function accessoryButtonTappedForRowWithIndexPath seems to bind the accessory button to a touch up inside event, which gets fired when you do a drag and lift up your finger after because your finger is still inside the button (which followed the drag).
I worked around this by using a custom button and attaching an UITapGestureRecongnizer to it.

UITableView loses selection after swipe

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.

UITextView Data Selectors Without User Interaction Enabled

I have a UITableView of custom cells that contain a UITextView.
I want the UITextView to have data detectors (so that you can tap on URLs), however, I also want the user to be able to tap on the table view cell to select it. With the data dectors, I must have user interaction enabled, but to select the cell when tapping on the UITextView, I must have it disabled.
Is there any easy way to go about doing this? Thanks!
Add a UITableViewCellAccessory (checkmark, disclosure indicator or others) to your cells. Then use the method tableView: accessoryButtonTappedForRowWithIndexPath: in order to detect click on the accessory.

How can I detect a right swipe on UITableCell and display a custom button instead of Delete button

I want to display a "Duplicate" button where the Delete button would usually appear if the user swipes from left to right on a UITableView cell. I understand I can add a gesture recogniser to the cell as per this example https://stackoverflow.com/a/6167841/2567126.
How do I create and place a button on the cell so that it appears in a similar manner to the Delete button to allow the user to confirm the action? The cells are just standard UITableViewCells with the default style.
You can change the title of delete button with delegate method - tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:.

Resources