Tweet Make sure you have JSON Framework installed first.
This is a continuation from First JSON Iphone application
So the last entry went into describing how we do very basic JSON. Now lets get into something a bit more complex. Here is what my array looks like in PHP.
$array = array( array( 'title' => 'Brown Dog', 'img' => 'http://iphone.zcentric.com/files/1.jpg', ), array( 'title' => 'Black Dog', 'img' => 'http://iphone.zcentric.com/files/2.jpg', ), array( 'title' => 'Two Dogs', 'img' => 'http://iphone.
Tweet If you want to show an error if the host is down it is pretty easy. This thinks you have read the other JSON posts. So look at the viewDidLoad function.
This is a continuation of Custom UITableViewCell
We are just adding a if {} else {} and if the data is nil, show an error.
- (void)viewDidLoad { // Add the following line if you want the list to be editable // self.
Tweet If you are attempting to write a Iphone application to talk to a webservice, JSON is one of the best ways to go. Now unfortunately there is no native support in the Iphone SDK for JSON. There is a project called json-framework that provides a framework called json-framework.
There is little documentation on how to install it though. Recently I found a news group posting on how to do it along with a dmg!
Tweet So today we will create our first view. This takes over where Create a new class left off. So you can grab the source code from there if you need to. I also edited the arrows for the rows by following this tutorial I created.
Also in the DataController.m class I am changing the names to something more meaningful.
[menuArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Browse", @""), @"title", nil, nil]]; [menuArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"
Tweet Now that we have two views nicely done, we want to be able to navigate back to the main view. We do this with a back view in navigation bar in the top.
Open up RootViewController.m and look for the viewDidLoad function. You want to add the following line to it.
self.title = @"Photoblog"; Then when you click on browse, it will show Photoblog in the back navigation.
Tweet So now that we have a working navigation based application. (download source here) We now want to move the data outside to a seperate class. We do this so we can use the data around the application and not just RootViewController class.
Do you get why? Its so we can use the data in the next view we will get into later.
So the first thing you want to do is create a data holder class.
Tweet I found a something a bit late what would of been nice to cover before. I guess it is better late then never right?
In offical IPhone apps there are arrows on each row you can click on that mean you can click here to users. We want to add these nice little arrows.
So open up RootViewController.m and look for the function cellForRowAtIndexPath and in the if (cell == nil) {} block you want to add a link for accessoryType so it looks like
Tweet So now that we have a hello world application that works, we want to add more items to the list. I would think most application will not have just one menu item. So here we go.
The easiest way to do this is create an array object that contains all of the menu items. I am not going to go into what everything is just the basic overview. If you want to learn I will point you to the documents on Apple’s website.
Tweet Now that you have a very basic app. If you click the menu button on the Iphone simulator, you will see the name of your app and above it is a nasty white box. If you want a nice little icon there you can just drag it to the application name root on the left side. For my examples that would be Photoblog. It will prompt you to import it and do so.
Tweet I will attempt to explain what the default files are. If I get these wrong please correct me.
So below is a screenshot of the default files that get placed in your project when you create a navigation based application.
CoreGraphics.framework / Foundation.framework / UIKit.framework – These files are created by Apple that contain all the framework code we will be using to create the applications. You will never have to touch these but they should always be in your application.