How can i refresh buttons inside a cell in CollectionView? - ios

Given that:
For example in a collectionView there are 8 cells & each cell has a button & an image.Buttons here will display Yes/No Option to the user. Out of 8 cells only 1 cell will show "Yes" and remaining cells should show "No".
What i am looking is?
When i tap on a different button then current button show display "Yes" and previous button display "No".
I don't want to reload entire collectionView or cells inside a section in collectionView.

You can make use of reloadItemsAtIndexPaths method of collection View to reload multiple cells(In your case 2 cell i.e the minimum number of cells to be reloaded) instead of reloading whole collectionView.Pass the indexpath of the cell that you want to reload
ex:
//Logic to change button title Yes to No comes here.
collectionView.reloadItemsAtIndexPaths([indexPath1, indexPath2])
indexPath1, indexPath2 are the index paths to be reloaded.

Related

tvOS - Reset CollectionView's focus at one point of time with remembersLastFocusedIndexPath = true [swift]

I have a setup a collection view with remembersLastFocusedIndexPath set to true.
CollectionView is designed such a way that it has nested collection views,
CollectionView
-> Section 1
--->Header
--->Cell nested with collectionview
-> Section 2
--->Header
--->Cell nested with collectionview
....so on....
There is pagination too.
Now if user scrolls to say 2nd item in 7th section and clicks menu in tv remote, I am scrolling collection to top. [either by setting content offset to 0 or scrolling to 0th index]
Requirement: After scrolling to 0th index, if user tries to focus on first cell in 0th section, I want focus to be at 0th index.
Issue: But now collection view remembers last focused index path and scrolls to 2nd item in 7th section.
Expected: I do not want collection view to remember the last focused index path in this case. In all other cases, it should be remembered. i.e, after scrolling to top, I want do something like
collectionView.scrollToTop()
resetFocus() //which should reset collection view's focus to initial index.
func resetFocus() {
//What should be written here to reset the focus of collection view.
}
try also implementing indexPathForPreferredFocusedView after you reset focus. Documentation here.

How to get the item values of CollectionView items with button action iOS Swift

My implementation is like CollectionViews in tableview cells like in the picture. I have one button in that button action I need get the items of all CollectionView cells of particular index. any idea to achieve this in simple way.
Check this for image of my implementation CollectionViews in tableview cells and need to get the items of particular rows

iOS Voiceover: Focus selected cell and not the first row

I trying to make my app accessible, in my interface I have a UILabel and a UITableView, the tableView have a selectedRow. The selectedRow is the row in the middle of table view, for example is the row 50 if I have 100 row.
My problem is when I swype in screen to go to my next element, in this case when I go from label to tableView, the focus go to the first index and not to my cell was selected.
How I can fix that?
Assuming you have only a label and a table view, the problem boils down to keep in mind the latest position of the cell when you move from the label to the table view.
The following algorithm may be used to solve this problem :
Create a temporary index path variable (tmpIP) containing the index path of the selected cell.
When the label loses the focus, the table view selects the cell with the latest tmpIP index path. The variable value is nil if no cell was selected before the label selection.
Take a look at the UIAccessibilityFocus informal protocol to handle the focus of an accessible element.

UITableView carry cache instead of visible cell

I have a table view displaying few table cells, eg: A, B, C.
I also have a button will filter certain cell and display some other cell.
Lets say all the cell will use the same instance, although it have been filter or reappear in the table view. It will not initialize again.
The problem is after i click on filter button, the visible cell become A,D,C.
when i click on the button on cell "D", the information displayed is belong to "B" which suppose filtered.
I tried [table reloadData]; but it still displaying what suppose filtered.
Remarks: The ways i filter is removeAllObject in the tableview, and verify each cell is valid to display on tableview and add each into the tableview again, instead of insert and remove.
Hi after you have fliltered your cell you need to change datasource as well and reload tableView. You have not changed dataSource so table still had A,B,C . That's why it's showing information related to B instead of B

Passing data between UICollectionViewCells

I am using a UICollectionView, in which one UICollectionViewCell covers the entire screen. Inside my UICollectionViewCell, I give people the opportunity to add text (UILabel), images (UIImageView) and color (UIColor). Now when the user navigates to the next cell i want the color, labels and image views to be displayed exactly as they were added on the previous cell. The users also have the option to pinch and pan the labels and images. In short, how can i pass on data from one cell to another?
I see several ways how to do this depending on your realization:
use global properties/ivars to store the selected data from user input.
In either case you probably handle UITextFiledDelegate methods in your controller or extract the cell by indexPath and copy values from the current cell to the next one.
And when the user presses the "Continue" button you:
1) If you create all you collectionViewCells at once in cellForItemAtIndexPath, then you should only reload the necessary cell via - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths and set the values you have saved previously.
2) If you create cells but the next one is not ready (for instance you save the memory) - all almost the same - you add a new cell to the collectionView and read the data from your properties.
3) If you have not a "Continue" button or/and user can swipe the cell in every moment - so you can reload the cell in scrollViewDidScroll(or scrollViewWillBeginDragging) or extract the existent by indexPath and modify it without reloading.

Resources