How to disable: Drag across UITableViewCell selects it - uitableview

When you drag over a UITableViewCell in a TableView, the cell gets highlighted ("selected"), but didSelectRow... is not called. I wish to disable that selection. How would I do that? Note that setting the selectedStyle for a cell to selectedStyleNone, or something like that, is not what I want. I really want the OS not to select it.
Thanks in advance,

I think the property your searching for is BOOL allowsSelection declared in UITableView. By passing "no" the tableViewCell is not selected when the user touches it. The same is true for BOOL allowsSelectionDuringEditing.
I hope that fixes your problem ;)

Related

M13checkbox inside UITableView cell fires when click on cell

as the title I'm can put M13checkbox inside the cell and all of it works fine, the only problem is when I click outside the checkbox, it also reacts, so the checkbox will be changing it's state
Can anyone help?
I'm assuming it's something about UIGestureRecognizer
Thank you
I figured out how to do it my simply disable tableview allowselection
self.yourtableview.allowsSelection = false
for anyone who needs to do what I was tring to do

Issue on UITableViewCell custom class and UITableView scroll

I created a custom class of UITableViewCell with some variables for different state on UIGestureRecognizer.
For exemple :
class CustomClass : UITableViewCell {
var isDisabled : Bool! = false
}
I have a swipe gesture to detect that the user want disabled the cell. So when the user swipe, I set my variable "isDisabled" to true.
Everything works fine until here.
But, if the first row has the variable "isDisabled" to true and I scroll in my tableView, the first row load at the bottom of the page has the variable "isDisabled" to true too, but the user don't say that he want this cell disabled.
So, have you any idea how I can solved my problem ?
Thanks
The issue you explain is regarding the reuse cells bahaviour of the UITableView. You can solve in different ways, I'll try to explain you one of them:
You can create a collection (Array, or something else) of Bool for example, with the size of the numbers of cells in your UITableView and whenever you detect a swipe gesture mark the position in the array for the indexPath.row to true or false depends of it state. This keep the status of the cells for each index.
I hope this help you.

UICollectionViewCell is being selected multiple times when scrolling down?

I have a custom UIView checkmark icon that shows up when the user taps a particular subclassed UICollectionViewCell. However, when I scroll the icon appears on multiple cells without the user actually tapping on those cells. From what I researched so far, it appears this is caused from the cell reuse.
What would be some good solutions to fix this issue?
Appreciate any help!
Good thing to do would be to create a property in your subclassed cell as isSelected. And then in the item creation method put a check
if (item.isSelected) {
//show checkmark
} else {
//remove checkmark
}
This way is the item does not have the iSelected Property set as true, the extra checkboxes will not come.

UICollectionView selection does not last

I have a UICollectionView I use like a tool selection container. You have many tools (the cells), when you select one, the former selected is deselected, and so on... You can only have one tool selected at a time.
The problem is that I can't manage to have the cells selected. When I tap the cell, the collectionView:didSelectItemAtIndexPath: is called. I then reload the selected cell to change it's appearance (I change the alpha of the image) by using the [collectionView reloadItemsAtIndexPaths:#[indexPath]].
Well that reloads the cell ok, except one damn thing: in the collectionView:cellForItemAtIndexPath: the cell never get the selected property set to YES! So I can never change the alphabecause I never know when I must draw a selected cell or not.
Worse: [collectionView indexPathsForSelectedItems] is always empty!!!
I don't even mention the collectionView:didDeselectItemAtIndexPath: that is never called...
Well, if someone can help me understand what is going on, thanks in advance...
When you call reloadItemsAtIndexPaths: the collection view discards those cells and creates new ones, therefor discarding the selected state of the cells.
I'd suggest a couple of different options:
1.) In collectionView:didSelectItemAtIndexPath: call cellForItemAtIndexPath: to get a reference to the selected cell and update it's appearance there.
2.) (My Favorite) Use a custom subclass of UICollectionViewCell if you're not already, and override the method setSelected:. There you'll be notified when the cell is selected and you can update the appearance from within the subclass.
With regards to selecting multiple cell at once, you should try the allowsMultipleSelection property [myCollectionView setAllowsMultipleSelection:YES] The docs for that are here: https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionView_class/Reference/Reference.html#//apple_ref/occ/instp/UICollectionView/allowsMultipleSelection
Otherwise, #daltonclaybrook's answer is sufficient.

TableView editing style

I've got a tableView with entries which the user should be able to edit. The special thing is, the tableView has a "right detail" style (a number) and I want this right detail to be replaced (animated if possible) with the standard disclosure indicator accessory, when the user hits edit.
How can I do this? Thank you!
Update: Thank you for the answers so far but could you maybe give me a code example for the part where the number gets replaced by the picture? Thank you!
You can make use of the UITableViewDelegate methods for editing such as tableView:willBeginEditingRowAtIndexPath: to perform your changes. Use cellForRowAtIndexPath: to get the UITableViewCell object.
You can use a custom cell here and do all those works. Here you can use the same cell and add a subview to that cell where you want that change to happen. Later depending on the state i.e; isEditing = True/ false you can display what you want.

Resources