UICollectionViewCell is being selected multiple times when scrolling down? - ios

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.

Related

UITableviewCell - Clicking on empty checkmark circle in edit mode does not select cell

I have a table view with several rows. I have enabled multiple selections in edit mode. When I toggle edit mode, I initially select all rows programmatically. Everything works fine except for re-selecting a row that was deselected by tapping on the empty circle where the checkmark was.
Table View Configuration:
Sample Cells, one has been deselected:
The interesting thing is that I can tap on the checkmark to deselect a row (didDeselectRowAtIndexPath is called), but immediately tapping on the same spot again will not call didSelectRowAtIndexPath. I have to tap on the main part of the cell. Naturally, this is not a good user experience.
Here is an overlay showing the areas that respond to taps highlighted in green.
I have been unable to find any events that are fired when tapping on the edit control of a deselected row. I have no code inside didSelectRowAtIndexPath or didDeselectRowAtIndexPath and I am just relying on the list of selected cells that the tableview maintains when the edit mode is toggled off. Any help isolating this issue would be greatly appreciated.
The problem ended up being that I was setting a backgroundView on my custom table cell and that was preventing the touches from getting to the right target.

Reload table view on editing UITextView inside UITableViewCells

I have some customised UITableViewCells which contain a UITextView and a set of buttons. The buttons in the cell should be visible only when the user tries to edit the text view in the corresponding cell.
So, if the user attempts to edit the textview in cell1, then the set of buttons should be visible below the textview in cell1 and the height of cell1 should also be increased. Now, if the user attempts to edit the textview in cell2, then the set of buttons should be visible below the textview in cell2 and the height of cell2 should also be increased, whereas the buttons in cell1 should get removed and cell size needs to be calculated accordingly.
For this I tried to reload the table view cells from textViewDidBeginEditing:. This is reloading the cells properly and shows/hides the buttons properly in the required cells, but does not allow proper editing of text view. When the user tries to edit with the textview, the tableview reload methods are invoked constantly and not allowing the keyboard to stand for editing.
Is it right to handle reloading from textViewDidBeginEditing: in first place ? is there some better way to do this ? please help.
First I would suggest that do not reload the entire TableView each time. Instead use the
reloadRowsAtIndexPaths
method to load only the cell in which you want modifications.
Next, to solve your issue regarding the textView, you could do something like this, declare a class property of bool type, and set it to false. When you reload your cell for the first time, set it to true. Now in the textViewDidBegin editing method, check for this bool. If it is set to true, that means you already have loaded the cell and you do not need to load it again, so in this case do not call the reloadRows method. Else if it is false, reload the rows and set this bool to true.
Now in the textViewDidEndEditing delegate method, set this bool to false again so that when a user taps on another textView in some other row, it is reloaded properly.
This logic may not be perfect, you may require some tweaking. But it will get the job done
Explicitly make the textfield as firstResponder
if buttonsDisplayed == NO {
reload cell
}
if textFieldIsFirstResponder == NO {
[textField becomeFirstResponder];
}

Reset values of all UITextfield in custom table cell

I have many UITextFields in 2 UITabBar and I am trying to create a reset button where the values of all UITextFields become blank so user can restart the whole process.
I have UITableViewCell class for each cell because the cell are custom and static cells.
I have Reset Button in my 3rd Tab and would like the values in Tab 2 and Tab 3 to clear.
I have tried creating instance of CustomTableViewCell and set the value of UITextField to blank but is not working.
Any help will be highly appreciated.
Thanks
Not sure what the UITableViewCells have to do with UITabBar but one solution that will surely work is: you listen for notification inside the cells and send the notification when reset button is pressed.
Other solutions depend on your implementation.

UIPickerView in UITableViewCell - how to select values instead of scrolling TableView?

I've got a custom UITableViewCell that has a label and a UIPickerView. Display works fine, but when I want to select a value in the Picker, the TableView scrolls. What can I do so that the gestures in the cell go to the Picker instead of the whole TableView?
The only solution I could come up with was to set the whole TableView to scrollEnabled = NO. This works for the Picker, but now I can't get to the cells under the custom cell. Control has to be more fine-grained.
If you can get hold of the UIGestureRecognizer for each of the two gestures, and tell one it needs to wait for the other to fail. With one in every cell, that becomes over-wieldy.
Perhaps you should add a control or have the accessory view "bring up" the picker, and then dismiss it when done.

How to disable: Drag across UITableViewCell selects it

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 ;)

Resources