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
Related
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
Hey,
I'm basically trying to retrieve data from SQlite db and populate a tableView from it.
The sql-data-retrieval method creates two arrays. "dataArray" and "SectionArray".
DataArray is filled with data NSObjects.
Uptil this point, i can create the appropriate Section headers.
Here is the problem,
-1 What do i do to make sure that the right objects get into their appropriate sections and not under any other sections (which they seem to be doing). Also the Count(number of rows) in each section differs.
What should the code be in "NumberOfRowsAtIndexPath" and cellForRowAtIndexPath methods
-2 What kind of datasource objects are more suited for this type. I'm simply filling up two NSMutableArrays - dataArray(rows) and SectionArray(Section headers).
I think you should make many NSArray one for each table header you have created. In NumberOfRowsAtIndexPath you will return the count of the array for the requested section, and in cellForRowAtIndexPath you will choose your array using the section index (as before) and with the row index you will select the row of that array.
I have a tableView controller with two sections. The first section has a couple of input fields and is not really displaying core data. The second section displays items from a database saved with Core Data.
I have an NSFetchedResultsController and I serve up data for cellForRowAtIndexPath and didSelectRowAtIndexPath as follows. For section = 0, I manually serve up the appropriate input fields, and for section = 1 I want to use [fetchedResultsController objectAtIndexPath:indexPath]. () However, since the fetched results controller only knows about one section, this doesn't work.
I know I can create a new IndexPath with section = 0, and then feed that to the NSFetchedResultsController. Is that the preferred solution or is there another way to 'tell' the NSFetchedResultsController what to expect?
The only way to do this is to translate the NSIndexPath objects passed into the various UITableViewDataSource/UITableViewDelegate methods into index paths appropriate for your NSFetchedResultsController. I'd recommend adding a method to your class that does this.
The return values from this method will match the section numbers the NSFetchedResultsController uses. Also, if in the future you end up needing a second header section for whatever reason, it's easy enough to adjust your method to do that.
Why would you need to tell it anything? In the delegate methods, just offset the section index by one and you should be fine.
You can create your own NSIndexPath instance to pass into the NSFetchedResultsController to resolve this issue.
Update
If you want to have two sections then yes that is the right answer. However I would consider putting your input fields into the table header instead of a section. That would be a cleaner answer in my opinion.
I have a table where there will often be two cells with the same title. I'm zooming in on a map whenever a cell in the table is clicked, so using the title as a unique identifier is out of the question. I already have a unique identifier, but I need to find a way to store it in a UITableViewCell object.
I have been considering two options, both of which are poor, IMO.
1) store the unique ID as the text inside the text of the detailTextLabel property.
2) build a custom UITableViewCell class.
I'm new to objective C, and I would essentially like to know if theres a third option that isnt as inefficient as #1, but not as involved as #2.
Thanks
Use the cell's tag property (works only if your identifier is an integer).
That said, cells already have a unique identifier (albeit not necessarily constant) and that is their indexPath, i.e. their position in the table. You should generally not use the cells to store any data directly. Instead, store the data in a model object and maintain the connection between model data and view via the indexPath.
This is especially important when dealing with table views as cell views get reused or deallocated as soon as a cell is scrolled off the screen.
If i have to show 10 or 30 or 100 strings in a uitableview..How to get the selected raw from that.. My value for each row is different .I mean i have to set the row value and display name from a 2 dimenional NSArray.. Somebody please help me..
I would setup an NSMutableArray of the objects your table rows represent. You can use your own class or NSDictionaries, one per row. My data source implementation (UITableViewDataSource protocol) of -tableView:cellForRowAtIndexPath: would set each cell's content (be it strings, images or anything else) to the appropriate object of the NSMutableArray. My delegate implementation (UITableViewDelegate protocol) of -tableView: didSelectRowAtIndexPath: would be called whenever a row is selected and the supplied NSIndexPath would point to the corresponding object's index in the NSMutableArray.
Basically, just implement UITableViewController which is by default both the data source and the delegate of the table view, put the objects you need to "show" in the table into an NSMutableArray and implement -tableView:numberOfRowsInSection:, -tableView:cellForRowAtIndexPath: and -tableView: didSelectRowAtIndexPath: in the most straight-forward manner. The first method returns the number of rows per section, the second configures a cell for each row, the third is sent when a row is selected.