Keep the UITableViewCell marked when switching from searchResultsTableView and tableView - ios

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.

Related

Filter tableview based on an item in another tableview

I have a UITableView displaying comments which are dynamically displayed through JSON. On the same page, I have another UITableView as a Filter.
The filter displays a list of the types of comments. I need to filter the main tableview based on the type of comment selected from the filter tableview.
Filter TableView1 based on item selected in TableView2.
TableView1 - Main tableview
TableView2 - Filter tableview
Following is an image of the page:
For instance, if I select "Worst Moments" in TableView2, TableView1 should display only those rows that contain the comment with "Worst Moments" as a keyword in it.
Can anyone help me with a code, how to filter items in TableView1 based on an item selected in TableView2?
Can anyone help me with a code
if you are asking us to code it for you then aside from the most generous souls here, most likely not.
You are almost there. This is how I would approach the problem
What you need to do is add UISearchBar to your ViewController
When an option is selected in TableView2 make it into a string
Pass that string to UISearchBar
Use that to refresh your TableView1
If you need some help you can either google UITableView & UISearchBar or you can check this Tutorial HERE.

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.. :)

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

Can i configure a section in UITableView to be multi-select

I have a requirement in my project, i want to configure a section to be multi-select in UITableView and rest of the sections as single-select. How can i achieve this ?
Any help will be appreciated.
Upon My understanding from your question you need to delete multiple row on an action(say button taping)
You can use a checkmark per selected row by setting the accessoryType on the selected UITableViewCell instances to UITableViewCelAccessoryCheckmark.
To deselect the row, set it back to UITableViewCellAccessoryNone. Manage some NSArray for the selected row like in your table view delegate in the didSelectRowAtIndexPath:" delegate method.
or
you can enumerate which cells/rows were selected , simply iterate over the cells of the table looking for UITableViewCellAccessoryCheckmark.
You can use following sample codes:
http://www.edumobile.org/iphone/iphone-programming-tutorials/multiple-row-selection-in-iphone-table-view/
https://developer.apple.com/library/ios/samplecode/TableMultiSelect/Introduction/Intro.html

Possible to allow a uitableview to allow multiple and single selections?

Essentially I have a list of items, I want to have some type of checkbox on the end where they can select multiple items. I also need them to be able to just select one of the rows and have it open up a detail view. Is this possible? Or do I need to do something like they do with the messages where you choose the edit button to select them and show an additional button to take action on the selected?
Set your cell's UITableViewAccessoryType property to UITableViewCellAccessoryCheckmark to make a check mark show up on a certain cell, you'll have to keep track of which cell's are checked on your own though, since this property doesn't track.
So have an array or something that represents which cells ar checked and which aren't, then in your didSelectRowAtIndexPath: method you can modify the data in the array to reflect the cell's selected state, and call [tableView reloadData] so the checkmark shows up right away.
I found the answer, there's an option to allow multiple selections on edit mode.

Resources