UITableView carry cache instead of visible cell - ios

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

Related

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.

Getting the data of all TableView Cell which all has TextFields in it (including the hidden views)

I'd like to get every data that is within all cells in one tableview which is quite a long list.
I'm looking for an approach on how to retrieve everything including those hidden in view, which I know the views are reused. I think some of you might have experienced this problem before, what are your approach on this?
I've tried
let cells = self.tableView.visibleCells
then looping into every cell and saving each data to an array but it is not effective in getting those that aren't part of the view or hidden. Is there a way to get over this?
In cellForRowAtIndexPath, YOU are telling the table what is in each cell. So why would you turn around and ask the table what's in each cell? If the user puts "Hello" in your first cell, then scrolls the table enough to push that first cell out of view, then when the user scrolls back to the top, YOU are the one telling it to put "Hello" back in that first cell. YOU own the data source, not the table.
You need a data source. That can be "empty" at first, maybe an array of empty strings if that's what you want (each index in the array could map to a table row for example). But then, as the user interacts with the text fields in the cells, you need to update that data source with the text they entered.
You should use that data source as your source for the cellForRowAtIndex method. That way you can handle populating the cells when they are requested by the table, and you also know all the data when the user is done.
Why not just update the model each time the user taps a key when editing a textfield? You could create a protocol for that cell subclass and make your view controller the delegate for each cell. As long as cells are guaranteed to stay on the screen while you're typing (you'll get some weird behaviors if not) the cell can send a message to the view controller or whatever you hook it up to telling it what new value to store. Then everything is already stored for you when you need the full list, and you don't have to interact with the tableview.

Information from a PickerView appears in another line of the TableView. How to solve?

Hello programmers friends. I have a situation I can not explain. I'll leave the prints on the screens and then describe what happened.
-
-
[-][3]
Initially I select the quantity in the pickerview and it changes in the UITextField field. Then when I scroll the screen, the 6 row of the table is with the PickerView information from row 1, and then when I roll the screen up, the data is lost. Has anyone ever had a similar problem?
When a quantity is selected, you need to persist that information in your data model. UITableView only creates enough rows to show what's visible on screen and it re-creates rows as they are scrolled into view. So you need to have the quantity information stored elsewhere to provide to the table view when it asks again for the row information. Hope this makes sense?
As Paulw11 mentioned, cells within a UITableView or a UICollectionView are reused, thus if you are manually creating the UIPickerView within the cell itself you have two options:
1) Rather than create the UIPickerView via code, subclass the UICollectionViewCell being used and add the UIPickerView either in the Xib / Storyboard(where ever you created the cell view).
2) In the prepareForReuse() function within a cell, check if the UIPickerView variable is not nil, and if it is not nil, then remove it and set it to nil.

UICollectionView showing selected cells

i have a tableview with form fields, and there is a row that use segue to call an UICollectionView, everything is works except that i can't keep the selected cells (the visual effect that i show when the cell is selected) after go back to the tableview.
I mean, i selected my UICollectionView cells, after that i go back to the form, but if i need to again to my UICollectionView Cells, to deselect o select more cells before submit the data, once the UICollectionView appear my previous selection are there (i print the array, and i see the values) but i cant see the effect that i did for selected cells.
How i can keep the effect for selected cells if I'm going back to select again o deselect cells?
One thing to realize is that this is not going to happen by itself. When you segue back to the table view and the form fields, the UICollectionView is completely destroyed. The next time you show the collection view, it is a new and different collection view.
So, if you want to maintain a knowledge of what the selection was in the collection view, you are going to have to maintain it yourself, deliberately, storing it somewhere when you know that the collection view is being destroyed.
That way, the next time you show your collection view, even though that will be a completely new and different collection view, you can pass the knowledge of what the selection was to that collection view as you create and show it. The user will have the illusion of "returning" to the collection view, in the same state, but in fact you will have saved and restored its state.
It is then just a matter of reflecting the selected state in the collection view's display of its items. To do that, you need to configure your model so that when cellForItemAtIndexPath: is called, each cell looks selected if that item is supposed to be selected.
Every time you use segue to call an UICollectionView a new instance of UICollectionView is created and hence states of selected cells doesn't get restored.
I believe u must have taken an array of index paths of selected indexes to show the visual changes in the cell.
Make your tableView class as delegate of UICollectionView. Using its delegate methods return the selected index array to tableView class .And before pushing to UICollectionView send the same array of index paths back to the UICollectionView. Hope it helps.. Happy Coding.. :)

Keep the UITableViewCell marked when switching from searchResultsTableView and tableView

I have a a table view that displays search results. I want to mark some cell checked when I select row at some indexPaths. and later when I try to search something and the search results contains the previous marked cell, how to show this cell which is marked in the search results tableview? Right now I am using a NSMutableArray to add and remove selected indexPaths when I select rows. But if I search in search bar, and previous marked cell won't been marked in search results tableview. What's the better to way to keep track of selected rows?
I would suggest you to add a BOOL selected to the model object you are using as the data source of the table view. You can set this value when you make a selection on the table view. While searching indexPath of the selected rows being changed but, if you mark the selection in the data source, it is not going to change.

Resources