<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhone Programming Tutorials &#187; UIScrollView</title>
	<atom:link href="http://www.icodeblog.com/tag/uiscrollview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icodeblog.com</link>
	<description>Conquering the mobile universe</description>
	<lastBuildDate>Tue, 06 Dec 2011 23:02:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using NSXMLParser to Pull UIImages From the Web</title>
		<link>http://www.icodeblog.com/2009/06/19/using-nsxmlparser-to-pull-uiimages-from-the-web/</link>
		<comments>http://www.icodeblog.com/2009/06/19/using-nsxmlparser-to-pull-uiimages-from-the-web/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 23:35:15 +0000</pubDate>
		<dc:creator>Collin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[NSXMLParser]]></category>
		<category><![CDATA[UIImage]]></category>
		<category><![CDATA[UIScrollView]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=945</guid>
		<description><![CDATA[Introduction
Hello everyone, welcome to my third screeencast. This screencast is the result of a request made in the comments of my <a title="Creating a Custom UITableViewCell using Interface Builder" href="http://icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/" target="_blank">first post</a>. I am going to be covering many topics in this post. But the general idea of the app we will build is that it will use an XML file online to get the URL and title of a given picture. For each URL and Title pair a view  ...]]></description>
			<content:encoded><![CDATA[<h1><span style="color: #ff6600;">Introduction</span></h1>
<p>Hello everyone, welcome to my third screeencast. This screencast is the result of a request made in the comments of my <a title="Creating a Custom UITableViewCell using Interface Builder" href="http://icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/" target="_blank">first post</a>. I am going to be covering many topics in this post. But the general idea of the app we will build is that it will use an XML file online to get the URL and title of a given picture. For each URL and Title pair a view will be created with a UIImageView showing the image and a UILabel showing the title. Each of these views will be placed in a UIScrollView to flip through, like th functinoality of the Photos app.</p>
<h2><span style="color: #000000;">Skill Level</span> <span style="color: #ff6600;">Medium</span></h2>
<p>This app is going to require a decent amount of experience with Objective C and xCode. Also some minimal understanding of XML and XML schema/structure would be valuable.</p>
<h1><span style="color: #ff6600;">Source Code<br />
</span></h1>
<h3><a title="Using NSXMLParser to Pull UIImages from the Web" href="http://staging.icodeblog.com/wp-content/uploads/2009/08/iCodeBlogXMLImage1.zip"><span style="text-decoration: underline;">Available Here</span></a></h3>
<h1><span style="color: #ff6600;">Screencast</span></h1>
<p>I film myself coding out the entire sample project for each post. I personally think going through the Screencast is the best way to learn. But feel free to look through the slides and text if that suites you better.</p>
<p><object width="600" height="375"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5515556&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5515556&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ff9933&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="600" height="375"></embed></object>
<p><a href="http://vimeo.com/5515556">iCodeBlog: Using NSXMLParser to pull UIImages off the Web</a> from <a href="http://vimeo.com/user2008025">Collin Ruffenach</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<h2><span style="color: #ff6600;">SCREENCAST ADDITION</span></h2>
<pre style="padding-left: 30px;">Adding a final line to layoutSubviews should be:</pre>
<pre style="padding-left: 30px;">Â     [scrollview setFrame:workingFrame];

this will stop the scroll view from bouncing up and down.</pre>
<h1><span style="color: #ff6600;">Tutorial</span></h1>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-947" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-322.png" alt="picture-32" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-948" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-411.png" alt="picture-41" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-949" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-51.png" alt="picture-5" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-950" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-611.png" alt="picture-61" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-951" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-711.png" alt="picture-71" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-952" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-811.png" alt="picture-81" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-953" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-911.png" alt="picture-91" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-954" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1011.png" alt="picture-101" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-955" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1111.png" alt="picture-111" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-956" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1211.png" alt="picture-121" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-957" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1311.png" alt="picture-131" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-958" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1411.png" alt="picture-141" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-959" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1511.png" alt="picture-151" width="620" height="387" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.h:</span></h2>
<pre style="padding-left: 60px;">@interface iCodeBlogXMLImagesViewController : UIViewController
{
	IBOutlet UIScrollView *scrollview;
}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollview;</pre>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.m</span></h2>
<pre style="padding-left: 60px;">@synthesize scrollview;</pre>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-960" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1611.png" alt="picture-161" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-961" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1711.png" alt="picture-171" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-962" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1811.png" alt="picture-181" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-963" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-1911.png" alt="picture-191" width="620" height="387" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLView.h:</span></h2>
<pre style="padding-left: 60px;">@interface iCodeBlogXMLView : UIView
{
	IBOutlet UIImageView *imageView;
	IBOutlet UILabel *title;
}

@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UILabel *title;

@end</pre>
<h2><span style="color: #ff6600;">iCodeBlogXMLView.m</span></h2>
<pre style="padding-left: 60px;">@synthesize imageView;
@synthesize title;</pre>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-964" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2011.png" alt="picture-201" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-965" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2111.png" alt="picture-211" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-966" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2211.png" alt="picture-221" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-967" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-231.png" alt="picture-23" width="620" height="387" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLElement.h:</span></h2>
<pre style="padding-left: 60px;">@interface iCodeBlogXMLElement : NSObject
{
	UIImage *image;
	NSString *imageTitle;
}

@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) NSString *imageTitle;

@end</pre>
<h2><span style="color: #ff6600;">iCodeBlogXMLElement.m</span></h2>
<pre style="padding-left: 60px;">@synthesize image;
@synthesize imageTitle;</pre>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-968" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2411.png" alt="picture-241" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-969" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2511.png" alt="picture-251" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-970" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2611.png" alt="picture-261" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-971" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-271.png" alt="picture-27" width="620" height="387" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.h:</span></h2>
<pre style="padding-left: 60px;">#import &lt;UIKit/UIKit.h&gt;
#import "iCodeBlogXMLElement.h"
#import "iCodeBlogXMLView.h"

@interface iCodeBlogXMLImagesViewController : UIViewController
{
	IBOutlet UIScrollView *scrollview;

	NSXMLParser *parser;
	NSMutableString *currentAttribute;
	NSMutableArray *xmlElementObjects;

	iCodeBlogXMLElement *tempElement;
}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollview;

@property (nonatomic, retain) NSXMLParser *parser;
@property (nonatomic, retain) NSMutableString *currentAttribute;
@property (nonatomic, retain) NSMutableArray *xmlElementObjects;

@property (nonatomic, retain) iCodeBlogXMLElement *tempElement;

-(void)layoutSubview;

@end</pre>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.m</span></h2>
<pre style="padding-left: 60px;">@implementation iCodeBlogXMLImagesViewController

@synthesize scrollview;
@synthesize parser;
@synthesize currentAttribute;
@synthesize xmlElementObjects;
@synthesize tempElement;

...

- (void)viewDidLoad
{
    [super viewDidLoad];

	xmlElementObjects = [[NSMutableArray alloc] init];

	parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://losectrl-gaincommand.com/iCodeBlogHelper/Tutorial3/iCodeBlogImageXML.xml"]];
	[parser setDelegate:self];
	[parser parse];
}

...

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{

}</pre>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-972" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2811.png" alt="picture-281" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-973" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-2911.png" alt="picture-291" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-974" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-3011.png" alt="picture-301" width="620" height="387" /></span></p>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-975" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-3111.png" alt="picture-311" width="620" height="387" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.m</span></h2>
<pre style="padding-left: 60px;">- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	if(![elementName compare:@"PictureInfo"])
	{
		tempElement = [[iCodeBlogXMLElement alloc] init];
	}

	else if(![elementName compare:@"imageURL"])
	{
		currentAttribute = [NSMutableString string];
	}

	else if(![elementName compare:@"imageTitle"])
	{
		currentAttribute = [NSMutableString string];
	}
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
	if(![elementName compare:@"PictureInfo"])
	{
		[xmlElementObjects addObject:tempElement];
	}

	else if(![elementName compare:@"imageURL"])
	{
		NSURL *imageURL = [NSURL URLWithString:currentAttribute];
		NSData *data =  [NSData dataWithContentsOfURL:imageURL];
		UIImage *image = [[UIImage alloc] initWithData:data];

		[tempElement setImage:image];
	}

	else if(![elementName compare:@"imageTitle"])
	{
		NSLog(@"The image title is %@", currentAttribute);
		[tempElement setImageTitle:currentAttribute];
	}

	else if(![elementName compare:@"Pictures"])
	{
		[self layoutSubview];
	}
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	if(self.currentAttribute)
	{
		[self.currentAttribute appendString:string];
	}
}</pre>
<p><span style="color: #ff6600;"><img class="aligncenter size-full wp-image-976" src="http://staging.icodeblog.com/wp-content/uploads/2009/06/picture-3211.png" alt="picture-321" width="622" height="388" /></span></p>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.m</span></h2>
<pre style="padding-left: 60px;"><span style="color: #ff6600;"><span style="color: #000000;">-(void)layoutSubview
{
	CGRect workingFrame;

	workingFrame.origin.x = 0;
	workingFrame.origin.y = 0;
	workingFrame.size.height = 480;
	workingFrame.size.width = 320;

	iCodeBlogXMLView *myView;

	for(iCodeBlogXMLElement *element in [self xmlElementObjects])
	{
		myView = [[iCodeBlogXMLView alloc] initWithFrame:workingFrame];

		NSLog(@"Element title is: %@", [element imageTitle]);

		NSArray *topLeveObjects = [[NSBundle mainBundle] loadNibNamed:@"iCodeBlogXMLView" owner:nil options:nil];

		for(id currentObject in topLeveObjects)
		{
			if([currentObject isKindOfClass:[iCodeBlogXMLView class]])
			{
				myView = (iCodeBlogXMLView *)currentObject;
			}
		}

		[[myView imageView] setImage:[element image]];
		[[myView title] setText:[element imageTitle]];
		[myView setFrame:workingFrame];

		[scrollview addSubview:myView];

		workingFrame.origin.x = workingFrame.origin.x + 320;
	}

	workingFrame.size.width = workingFrame.origin.x;
	[scrollview setContentSize:workingFrame.size];

	workingFrame.origin.x = 0;
	workingFrame.origin.y = 0;
	workingFrame.size.width = 320;
	workingFrame.size.height = 480;
}</span>

<img class="aligncenter size-large wp-image-996" src="http://icodeblog.com/wp-content/uploads/2009/06/picture-33-1024x640.png" alt="picture-33" width="623" height="389" />
</span></pre>
<h2><span style="color: #ff6600;">iCodeBlogXMLImagesViewController.m</span></h2>
<pre>	parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://losectrl-gaincommand.com/iCodeBlogHelper/Tutorial3/iCodeBlogImageXMLB.xml"]];</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.icodeblog.com/2009/06/19/using-nsxmlparser-to-pull-uiimages-from-the-web/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
	</channel>
</rss>

