Posts List

Click a Cell

Tweet Make sure you have JSON Framework installed first. This is a continuation of JSON Error So here is a quick tutorial on how to click on a cell and load some JSON data for that cell. So the idea is you have a unique ID for each set of data you have. So for that I am going to change the php code to add a ID <php header('Content-type: application/x-json'); $id = (int)$_GET['id']; $array = array( 1 => array( 'id' => 1, // added this 'title' => 'Brown Dog', 'img' => 'http://iphone.

Using NSUserDefaults

Tweet This will go over a quick run through of using NSUserDefaults. This is the class to use to save user preferences for example. It is pretty straight forward. Saving Data This is how you save data. NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // saving a string [prefs setObject:@"test" forKey:@"stringVal"]; // saving a int [prefs setObject::23 forKey:@"intVal"]; // saving it all [prefs synchronize]; Loading Data NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; // getting the string stringVal = [prefs stringForKey:@"stringVal"]; // getting the int intVal = [prefs integerForKey:@"intVal"]; That is it.

Create a text input

Tweet So here is a quick no real code tutorial. This is another thing that took me a bit to figure out. For this example, I am putting a text input in a TableView. So here is my class declaration. @interface OptionsViewController : UITableViewController <UITextFieldDelegate> { } You need to put the UITextFieldDelegate as a reference class. Now I am going to create the text input in the .

Add a navigation button

Tweet This will pickup where Create a view left off. So you can pick it up from there and download the source. You probably don’t even need the source but grab it if you wish Now when you create a new view, in that view you might want to place a button in the navigation bar. This is pretty easy to do. So you want to open up the sub-view controller.

More Complex JSON endpoint

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.

JSON Error

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.

Install json-framework

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!

First JSON Iphone application

Tweet So now that we have the basics of installing JSON to our project, lets make a test application. I started by creating a new project and used the Navigation Controller Template. The first thing you want to do is setup your JSON environment as explained in the previous post and again you can visit the link above for instructions on how to do that. Once it is setup you are ready to code.

Custom UITableViewCell

Tweet Make sure you have JSON Framework installed first. This is a continuation of More Complex JSON endpoint The reason why OOP is so powerful is that you can subclass everything to make it work or look just how you want it. The default look of a UITableViewCell is just one line of text. If you want to add some text below it you need to subclass that. So that is what we will do right now.

Add a back button

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.