Multiple selection in UITableView. And the tables are dynamically generated - iphone

I have multiple uitableviews.
I created the multiple tables by using a loop.
The number of tables depend on the result of the webservice.
And each table have multiple selections. I have to pass all the values selected from every table to next webservice.
How can I do this task ?
Thank You,

1-> you can use check Boxes for in your UITableView for mutli section (Check box can be implemented by UIButton). one check box per row.
2-> Use a flag (BOOL isSelected),set it true when user select a cell (tableView:didSelectRowAtIndexPath:),and make it false for next touch,
for second approach you could use a custom UITableViewCell and use a image to show cell selection to the user (image can be changed by using isSelected value in tableView:didSelectRowAtIndexPath: method.

Related

Saving Order on UITableView data

I have created a reorder-able UITableView. I am loading data from Realm, and showing that data into UITableView. My UITableView has Section and rows.
now User can hold Any cell in any section and can reorder them in 2 ways
User can reorder cell with in the same section.
User can reorder cell across the different section.
What I need:
Once the user has made the order he should see same item in same order
when he come back to App. For any type of reordering I have to do
indexing. But I do not have clue how to reorder them in database.
My Idea to resolve the requirement
My idea is to include the String type value in the Model where I can replace something like (1,10) that will indicate section 1, row 10.
But I do not have idea how to tackle this and how to save the reordering as i need here. Any idea about that?? please share

NSTableView multiple Selections

I have an NSTableView with multiple selections enabled
If I select items and scroll the list back and forth they are remember and shown and selected (blue background).
Using the didDeselectRowAtIndexPath and didSelectRowAtIndexPath I am able to keep my own array of selected items.
that part works well.
However If I then use the sectionForSectionIndexTitle and jump to a letter The selection appears to be forgotten even indexPathForSelectedRows appears to have been reset and is now empty.
My own array remembers that an item is selected and I can set the cell.selected in the cellForRowAtIndexPath but the instant I move the list it is forgotten again
Any ideas is this a bug or how do you retain the selection list when jumping to a letter
Thanks in advance
Remember the UITableViewCells are there to display your data only and by no means they have a 1-to-1 relationship with your "model" as the are queued and reused when necessary (i.e. you may have thousands of items on display in a tableview but only a handful of instances of UITableViewCell allocated).
So you need to keep track of the selected / deselected items in a mutable array and make sure that you check for the presence of that item in your tableView:cellForRowAtIndexPath: method and then update the cell properties to represent your data.
By using an NSMutableArray of selected row values, it may be possible to keep track of the selected rows in the table yourself. Then it would be a matter of calling -selectRowAtIndexPath:animated on the last object in the array to restore the selections.
As for the bug: what could possibly be happening when the table jumps to a selected letter, is a stray -reloadData which would forget the selected row(s).
I think it is happening because your cells are reused. Do not reuse the cells(you are not using your cells efficiently). otherwise,
You can store the selection by yourself in an array and use it later for your purpose.!

Mapping a dataset to textfield inside UItableView

In my app, I am using some .net asmx services (as backend) to get some data and populating it on my views. In one of the modules, i need to edit and save the data which am getting from the services.In that am getting several rowkeyvalues and accordingly am creating those many row cells in my tableview, which consists two UItextfields as well, which displays some unique code and comments.
Now if I have to edit and save some fields, I need to map each one of those rowkeys to each row cell and after that am creating object which is basically the wsdl proxy class which I have generated using Sudzc and pass each dataset and serialize it to XML and POST it through SOAP.
The real problem here, am not getting how to map each unique rowkeys to each row cell and create unique dataset(which mainly contains other fields as well including rowkey) for each row and pass it to proxy object (WSDL stubs).
Not sure I understand your problem, but there are 2 ways I can think of to map a row cell to something.
1. Each UITableViewCell is a subclass of UIView, and so it has a "tag" attribute, which is an int.
You can set this and check it's value.
2. When a user taps a row, the tableView:didSelectRowAtIndexPath: is called. IndexPath.row is an int that gives the absolute row postiion within it's section (and if only one section, then in the whole table).
Usually, in cellForRowAtIndexPath: you fetch your backing data corresponding to the IndexPath.row and populate the cell. You could also set the cell's tag at that point.
This ties together the row, the cell and the data.
Hope that helps.
-Mike

Update tableView with AccessoryCheckmark when switching back to that TabView

My app has 3 tabs, and the array that populates a tableView in third tab can be changed in the other two tabs. When I switch to the third tab, I need the tableView to be updated. I know how to do this, the only problem is that the table view is a check list.
When I tick some of the rows in the third tab, switch to another tab and update the 3rd tab's array, when I want to switch back to the third tab the table is updated with the new data but the checkmarks are removed from the table.
Is there a way to update the table without removing the checkmarks?
How are you determining whether an item is checked right now? It sounds like you may not be storing the checked status of the object, and instead just setting the accessoryType on the cell to UITableViewCellAccessoryCheckmark. If so you need to add a boolean property to the objects stored in the array that will represent whether that item is currently checked or not.
Once you have this value stored you can use it when configuring your tableview cells(either in tableView: cellForRowAtIndexPath: or configureCell: atIndexPath: or wherever else you do cell configuration) to set the appropriate accessoryType for the cell.. Putting this in your cell configuration will get the tableview to correctly check items when reloading the tableview.
Are you reloading the tableview when you tap on 3rd button or creating new tableView.
If you are reloading, Use temp variable to store the data of Checkmarked cell. On every reload compare the temp data with data of cell .If it matchs place checkmark.
when you are adding objects to the array then there you can add a dictionary object, with an extra object #"FALSE",#"checkState". Initially it will FALSE for all objects, so when you are creating cells for table in your third tab check for that key in array. And when you select a cell then access the dictionary object for that indexPath.row in array and update its value to TRUE for key #"checkState".

Is it possible to preload all the cells in a uitableview?

Is there a simple way to preload all the cells in a uitableview?
I need to do this in order to change whether or not all the cells are checked. If I just use cellForRowAtIndexPath, and the user say unchecks all the cells, and then checks a visible cell and starts to scroll again, either the selected cell gets deselected or the newly loading cells are selected.
It seems the easiest way to go would be to preload all the cells if possible.
Thanks!
Don't use the cells as your database.
Your cells are just a narrow window onto your data. The cells just show you a few of the objects in the underlying data. If you try to preload all the cells so you could then select them all, the UITableView could die a slow death, or slow crawl. Especially if we're talking hundreds of entries.
If you want to select all the items in your data, you do so with a direct call to your data to select its objects. Then, you reload the data into your TableView with a reloadData and if everything is set up right, your cells will show the selected state.
Read up on UITableView. Look at Apple's samples. You need to see the separation of data from the view and the controller.
Please re-read the answer I wrote here to your previous, similar question, which explains one solution to your problem.
Again, you should consider keeping an array of on/off settings. You can use NSMutableArray or a C array of int or BOOL values, whatever you want. But it definitely sounds like you need a data model.
Your -tableView:cellForRowAtIndexPath: looks up values of this array. Each value in the array corresponds in some way to a row in the table.
If you only have one section, then you can simply use the ith element of the array to set the checked state of the ith row of the table view. If you use NSMutableArray to store NSNumbers, you can handle resizing quite easily.
If you have more than one section, keep an array of arrays. Each top-level array corresponds to a section. Each inner array corresponds to a section's rows.
If you use NSMutableArray to store NSMutableArrays of NSNumbers, you can handle resizing and section addition and deletion quite easily.
The method -tableView:cellForRowAtIndexPath: then sets up cells with or without checkmarks, depending on the array's value.
Having a data model gives you the freedom to programmatically perform "select all" and "deselect all" button operations.
For example, when you click a button to "select all" cells:
Loop through the array and set each value to YES or 1 or whatever "on" label you chose originally.
Call [tableView reloadData], which is a method that goes back to -tableView:cellForRowAtIndexPath: and which will set a cell's checkmark state based on the state of values in the updated array.
No, you can't do this. You seem to be under the impression that a cell represents a particular piece of data, it doesn't. When the top cell scrolls off the screen it is usually recycled and brought in as the bottom cell. So a list that has hundreds of items you can scolled through may only ever have 8 or 9 cells alloc'ed and initialized.
You need to rethink your application's architecture. When you "uncheck all" it shouldn't change the visual state of the cell, it should change some state in the objects the cell represents, then when you load the cell for the object at that index path you should read that state and set the check mark appropriately.
The changes in the visual state of your cell should always be in response to changes in your underlying model.