Refreshing table data that is retrieved dynamically from JSON - iphone

I am retrieving the Json data from an URL into a table view. The problem is that i couldnt replace the old data that is retrieved, with the new data when i click another table cell. The new data is getting added to the last cell of the table cell while the old data is also getting displayed. What could be the problem...

You have to replace the data for the current cell with the new data then call the reloadData method on your tableview.
I mean you need to change the data in the array / datastore you pull from when rendering your cells in your delegate methods.
By replacing the code when the table view requests all the data & cells for rendering your delegate methods will pull the new data down and return an updated cell.

Related

save new and edited table values into core data

i searching for the best way to realize the following situation:
i have data in my core data.
i open the view controller with my tableview
this tableview fetchts the core data values
but now the questions:
how should i solve the situations for new values and edited values:
Situation 1:
i can add a row with a button and fill it with data
Should i directly save it into core data, each time if a row is added?
Situation 2:
if i edited an exist row, should i directly update the exist record?
At the moment:
I request the records and save them into an array.
and all new changes will be apply to the array.
if the view will disappear, i delete all the requested records in core data and save the array value into core data. is this a good way? i think not ...

Update table cell on notification

How can I update a tabelview cell when a particular notification received, without reloading table data. notification tells the id of the cell that I need to update. So I want to iterate all table cells and update only the relevant table cell without reloading it. how can i do this
Use [tableView visibleCells] to get a list of all cells that are displayed. Iterate through this array to see if the cell you need to update is displayed, then do whatever you need to. (this method is if you're reusing cells).
You can just use the built in reloadRowsAtIndexPaths:withRowAnimation: instead of trying to usurp the framework's functions. This will efficiently only reload the cell you ask it two not the entire table or even an entire section.
Reloads the specified rows using a certain animation effect.
Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it
animates the old row out. Call this method if you want to alert the
user that the value of a cell is changing. If, however, notifying the
user is not important—that is, you just want to change the value that
a cell is displaying—you can get the cell for a particular row and set
its new value.
When this method is called in an animation block defined by the beginUpdates and endUpdates methods, it behaves similarly to
deleteRowsAtIndexPaths:withRowAnimation:. The indexes that UITableView
passes to the method are specified in the state of the table view
prior to any updates. This happens regardless of ordering of the
insertion, deletion, and reloading method calls within the animation
block.
Available in iOS 3.0 and later.

How to access UITableViewCell that is out of view on a data entry screen to validate content?

I have a UITableView that contains data entry fields whose total height is about 2 screens tall. After entering data in the fields the user taps the Save button in the UINavigationBar then the contents of all the fields is validated.
If field #1 (topmost) is out of view because the user has scrolled to the bottom of the table then the UITableViewCell that contains the UITextField w/ the value is not accessible. Trying to access the cell/field using cellForRowAtIndexPath returns nil.
What would be the best approach to access all the fields in order to validate the field contents?
The best approach would be to store all of the data as it is entered in the fields, and then query your model for the data when you need it, rather than depending on the data being stored in the view.
You have a few options
What I do - store the text from the fields somewhere else and then use that
Store all of your cells in memory all the time so that they never get reused
Temporarily make your table big enough to hold all of your cells when you're doing the validation
Note that you can do number 3 without the change ever being visible.

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

Refreshing/releasing 2nd tableview from previous query in drill down tableview

I have a drill down tableview that is using sqlite.
The first one is a tableview where i load some categories using a SQL query.
When i click a row it's using the following query to show the appropriate records for the category:
#"SELECT * FROM table WHERE category IS ('%#')", sharedSingleton.category];
This works.
When i click the back button on tableview 2 and return to the category tableview and then touch another category tableview2 still shows the rows for the category i selected the first time.
I'm new to this stuff but i searched a long time and tried releasing objects or set value's to nil but is doesn't seem to help.
Am i in the right direction, how can i refresh or release tableview2?
Thanks in advance.
Yes you are in the right direction.
When selecting a row table 1 you might be calling a method which loads the second table view and assigning the data to be loaded to the corresponding table view,Which is fetched and filled when delegate/ data source methods of table view is called.
You might have created tableview as a different view controller class, which is initialized and data is reloaded for the first time. But even though you are fetching the second set of data its not getting reloaded automatically even after you are assigning it.
After assigning the data you have fetched into the obect which distributes it to tableview Reload the table data once you assign it to. you could call the one line of code to do this
[tableview reloadData];
Regards,
Jackson Sunny Rodrigues