Json - iPhone app: uitableview and uiwebview - iphone

I am quite new to Xcode and Json.
In my app, I have navigation through pages via tableviews (drill down). What I want to do now, is to use Json to create my tableviews and then when I select a cell in the uitableview, it will go to a website through the next page via a uiwebview.
How will I do this?

Parse your json using a parser
Create the parsed response as a data model for table view. You can use a Dictionary/array to keep things simple
Implement the tableview delegate methods and get the selected index
On didselectatrowindex method you create a new view, fetch the url from your model and load it into the webview.
I could write some code but thats really too much you are asking for. If you get stuck in any of the steps above, do leave a comment. I will be glad to help you out.

Related

Lazy Loading for multiple UITableView in one view

I am working on iPad app. And I am using 2 tables in one view and images urls are coming from
web services. I am using Apple provided lazy loading for both tables, and there are 2 web-service called for showing the two tables data, one is calling in ViewDidLoad() and second is calling in callback method of first web service. And I am facing problem in this method.
- (void)appImageDidLoad:(NSIndexPath *)indexPath withDataReceived:(NSData*)receivedData
The values for indexpath.row values are changing every time , some time it gives correct value and some time not.
Can anybody please help me for that.
Thanks in advance.
you might have to pass in which tableview also.. you kno how it is passing indexPath to that method.. modify it to pass tableview.. and inside the method.. check which tableView and then get the right data source array for appropriate tableview..

iPhone - Correct use of didSelectRowAtIndexPath

I'm a little confused as to how I should be using didSelectRowAtIndexPath.
Without using datasources (keeping things simple),if you display a list of names with UITableView and all you want to do is select a name and return it to whatever parent view controller created the UITableView list.. what would you do?
I'm used to Windows MFC programming where you have a dialog class and you call DoModal() to display the dialog and then query member variables of that dialog object to get the results.. With iPhone programming I'm confused with the whole paradigm. I push the UITableView into action, but at what point should I try and retrieve the results? pushViewController is asynchronous in nature isn't it? So I can't expect to retrieve results on the line immediately following the pushViewController method?
I'm using NSMutableArrays of NSStrings to keep things simple.
The patter you are going to use is called delegation, what happens is that you call the new ViewController and let it do its work, the function that called this will return normally,
Now you need to implement didSelectRowAtIndexPath and get the selectedRow, after this you will need to return the selected index or value to the original view controller( this will be recieved in another function) please read more about #protocol and delegateion

Preload data in a user friendly way

My application consists of data downloaded from an XML file. data contains short text and images.
currently I'm downloading up all data and building up the view in a view controller, in the ViewDidLoad method, which causes the application not to show up the root view until all data is downloaded. I want it to show up in a more user friendly way, at least to preload some of the data during the splash screen.
By the way I've done the lazy image loading so images can load while the main view is displayed.
As long as the number of views depend on number of rows in XML, loading XML asynchronously while building up the the view does not suite my need (or maybe I'm wrong).
I understand that describing the solution in an answer is quite a challenge, so maybe you could point to an article or even a book that has a detailed explanation of asynchronous and multithread handling.
I don't see why you can't load it asynchronously o_O
You should show some "Loading" view anyway (preferably with an activity Indicator)
A progress bar would be nice, too.
And when it's done downloading you just reload and relayout your view.
If by "number of views" you mean the number of cells in a table row you can just tell the tableview to reload all data whereas your numberOfRowsInSection function (or whatever you want to use) should return appropriate values depending on whether it's loading or not.
EDIT: you shouldn't do that while the application is still loading because that's extremely user-unfriendly and slows down the loading of the application aswell
I think you should parse all data in didFinishLaunchingWithOptions: method of appDelegate and then use following methods to do parsing.
[self performSelectorInBackground:#selector(downloadData:) withObject:nil];
method downloadData: contain parsing procedure.

Message users while large table loads

I am processing several large RSS feeds and displaying results in a TableView. The processing starts after the user clicks on the relevant tab. All works well, but as it takes a couple of seconds to process, the NIB and Table don't load until the processing finishes and it looks like the iPhone has seized up. I have added an Activity indicator to the NIB, but because it doesn't load until the table is ready to display, it appears too late to be of any use.
Does anyone have any ideas how to display a message to a user while the table builds/loads? I have tried loading a UIView first and adding the Table as a subview but, again, both seem to load only after the table is ready.
Guidance appreciated.
It's kind of hard to guess what's going on from your description but it looks like your calls aren't asynchronous. Here's what you should be doing in your code:
Make all calls asynchronous. You said your phone is seizing up. Makes it sound like your requests and responses are happening on the main thread. There are many libraries you could use to handle asynchronous calls. ASIHTTPRequest for one example....
Don't wait for the data to come in before displaying the tableView. It's a design principle that you load as much of the UI as possible so that the user has something to look at while your data loads up in the background. What you should be doing is initializing an NSMutableArray to hold the data. Initially this array will contain no objects. This is the array that you use in your data source methods: Use array size for numberOfRowsInSection and use the array objects in cellForRowAtIndexPath. Once your RSS feed XML comes in and is parsed, store that in your arrays and call [tableView reloadData]. This way you don't leave your users looking at a blank screen. (Another good practice is when the array size is zero, show one cell in your tableview that says "data is loading" or something).
When you first initialize and load up your table and then fire off those RSS feed requests, that's where you show an activity indicator view on the tableView. Stop animating the indicator when the RSS data comes in and your tableView reloads.
These are the standard steps you should follow while showing non local data in a tableview. Makes for a smooth user experience.
Like I said before, it seems from your question that your calls are not asynchronous. If I'm wrong, correct me and let's take it from there...

Problems getting an xml feed parsed and loaded into a tableview using delegates

Very new to programming for iOS and Cocoa so please take it easy on me as I try to wrap my brain around the following. I'm trying to display a tableview populated from an XML feed as the opening screen of my app. I've tried to consume the XML from inside my AppDelegate using the ApplicationDidFinishLaunching method (and then making my AppDelegate a delegate for the XML parser which I access using a NSUrlConnection and its delegate methods) but I can't figure out how to take the parsed XML file and pass it to a tableviewcontroller which can then use it as the datasource for a tableview. When I do try, I always get a blank tableview.
I've written the code a few times and nothing seems to work.. I'll post what I have here to show what I've got so far but I'm afraid its mostly vanilla AppDelegate with a few parser methods thrown in.. any pointers in the right direction would be super appreciated.
Thank you in advance!
Hmm, probably a bad idea to do the network call in the AppDelegate. Try to put all that code at the view controller level. Here's a brief structure of what I do (Since it's very similar)
View Controller listens to button events
Use ASIHTTPRequest to talk to your web service. Handles network really well, you can skip the NSURLConnection stuff.
Try to load your data source (an array?) with static values and see if they come up on the table view.
Parse the response from ASIHTTPRequest using NSXMLParser, and load the data you want into the static array you were using. More here.
Call [tableView reloadData] once you're done and the changes will reflect.
Did you specify a UITableViewDataSource for your table view and implement the two required methods?
tableView:cellForRowAtIndexPath:
and
tableView:numberOfRowsInSection:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
When I get blank tables, this is what it is; I've forgotten to specify the data source