Learning iPhone Programming by Alasdair Allan

Learning iPhone Programming by Alasdair Allan

Author:Alasdair Allan [Alasdair Allan]
Language: eng
Format: epub
Tags: COMPUTERS / Hardware / Personal Computers / Macintosh
ISBN: 9781449382865
Publisher: O'Reilly Media
Published: 2010-03-02T16:00:00+00:00


Populating the UI

Now that we’ve populated the data model, let’s create the updateView: method in our view controller. This is where we take the data that we just parsed from the XML and push it into the current view. Replace the updateView: method in MainViewController.m with the following:

- (void)updateView { // City Info nameLabel.text = forecast.location; dateLabel.text = forecast.date; // Now nowTempLabel.text = forecast.temp; nowHumidityLabel.text = forecast.humidity; nowWindLabel.text = forecast.wind; nowConditionLabel.text = forecast.condition; NSURL *url = [NSURL URLWithString:(NSString *)forecast.icon]; NSData *data = [NSData dataWithContentsOfURL:url]; nowImage.image = [[UIImage alloc] initWithData:data]; // Day 1 dayOneLabel.text = [forecast.days objectAtIndex:0]; dayOneTempLabel.text = [forecast.temps objectAtIndex:0]; dayOneChanceLabel.text = [forecast.conditions objectAtIndex:0]; url = [NSURL URLWithString:(NSString *)[forecast.icons objectAtIndex:0]]; data = [NSData dataWithContentsOfURL:url]; dayOneImage.image = [[UIImage alloc] initWithData:data]; // Day 2 dayTwoLabel.text = [forecast.days objectAtIndex:1]; dayTwoTempLabel.text = [forecast.temps objectAtIndex:1]; dayTwoChanceLabel.text = [forecast.conditions objectAtIndex:1]; url = [NSURL URLWithString:(NSString *)[forecast.icons objectAtIndex:1]]; data = [NSData dataWithContentsOfURL:url]; dayTwoImage.image = [[UIImage alloc] initWithData:data]; // Day 3 dayThreeLabel.text = [forecast.days objectAtIndex:2]; dayThreeTempLabel.text = [forecast.temps objectAtIndex:2]; dayThreeChanceLabel.text = [forecast.conditions objectAtIndex:2]; url = [NSURL URLWithString:(NSString *)[forecast.icons objectAtIndex:2]]; data = [NSData dataWithContentsOfURL:url]; dayThreeImage.image = [[UIImage alloc] initWithData:data]; // Day 4 dayFourLabel.text = [forecast.days objectAtIndex:3]; dayFourTempLabel.text = [forecast.temps objectAtIndex:3]; dayFourChanceLabel.text = [forecast.conditions objectAtIndex:3]; url = [NSURL URLWithString:(NSString *)[forecast.icons objectAtIndex:3]]; data = [NSData dataWithContentsOfURL:url]; dayFourImage.image = [[UIImage alloc] initWithData:data]; [loadingActivityIndicator stopAnimating]; }

We’re done. Click the Build and Run button on the Xcode toolbar to build and start the application in iPhone Simulator.

Once the application starts up, if all goes well you should get something that looks similar to Figure 7-15. There is, after all, almost always a chance of rain in London.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.