parsing xml file in ipad - ipad

?xml version="1.0" encoding="UTF-8" ?> <IPAD version="1.0">
<articleSnapshot>
<item>
<categoryName>Kerala</categoryName>
<oid>2915</oid>
<title>ÎÆcÈÏ¢: ÄßøáJW ÕçKAá¢</title>
<thumbImage>http://122.248.234.55/v3/repository/images/news/bar-liquor_thuthumb_2915.jpg</thumbImage>
<shortDescription>ÎÆcÈÏÕᢠ¥Äßæa dÉ~cÞÉÈÕáÎÞÏß ÌtæMGí ©ÏVK ÕßÎVÖÈBZ ÏáÁß®Ëá¢...</shortDescription>
</item>
</articleSnapshot>
</IPAD>
I want to parse this xml file and display it in viewdidload.i have completed the coding.but cant display in image view and textview seperately.Please help me.

This is how I parse an XML file very similar to yours. This basically converts the XML into a plist file.
#pragma mark - Delegate Received
-(void)parsingComplete:(XMLDataSource*)theParser {
NSArray *categoryArray = [theParser getCategories];
[categoryArray writeToFile:PLIST atomically:YES];
}
- (void)receivedItems:(NSArray *)theItems {
NSMutableArray *dataItems = [[NSMutableArray alloc] init];
[dataItems addObjectsFromArray:[NSArray arrayWithContentsOfFile:PLIST]];
NSDictionary * dataItem = [dataItems objectAtIndex:categoryIndex];
data_ = [dataItem objectForKey:#"images"];
}
#pragma mark - Parsing Delegates
- (void)parse:(NSData *)data withDelegate:(id)sender onComplete:(SEL)callback
{
parentDelegate = sender;
onCompleteCallback = callback;
loading = YES;
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
parsed = NO;
loading = NO;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSString *element = [elementName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
currentElement = element;
if ([[currentElement lowercaseString] isEqual:#"image"]) {
inImage = YES;
itemsDictionary = [[NSMutableDictionary alloc] init];
[itemsDictionary addEntriesFromDictionary:attributeDict];
}
if ([[currentElement lowercaseString] isEqual:#"category"]) {
inCategory = YES;
categoryDictionary = [[NSMutableDictionary alloc] init];
[categoryDictionary addEntriesFromDictionary:attributeDict];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
NSString *element = [elementName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([[element lowercaseString] isEqual:#"image"]) {
inImage = NO;
[items addObject:[itemsDictionary copy]];
}
if ([[element lowercaseString] isEqual:#"category"]) {
inCategory = NO;
[categoryDictionary setObject:[items copy] forKey:#"images"];
[items removeAllObjects];
[categories addObject:[categoryDictionary copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSString *stringValue = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *element = [currentElement stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
/* skip over blank elements. */
if (stringValue == nil || [stringValue isEqual:#""]) {
return;
}
if (element != nil && [element length] > 0) {
if (inImage) {
if ([itemsDictionary objectForKey:element] != nil) {
[itemsDictionary setObject:[NSString stringWithFormat:#"%#%#", [itemsDictionary objectForKey:element], stringValue]
forKey:element];
} else {
[itemsDictionary setObject:stringValue forKey:element];
}
} else if ((!inImage) && (inCategory)) {
if ([categoryDictionary objectForKey:element] != nil) {
[categoryDictionary setObject:[NSString stringWithFormat:#"%#%#", [categoryDictionary objectForKey:element], stringValue]
forKey:element];
} else {
[categoryDictionary setObject:stringValue forKey:element];
}
} else {
if ([root objectForKey:element] != nil) {
[root setObject:stringValue forKey:element];
}
}
}
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
NSError * err;
if(![[NSFileManager defaultManager] fileExistsAtPath:PLIST]) {
[[NSFileManager defaultManager] removeItemAtPath:PLIST error:&err];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
parsed = YES;
loading = NO;
if ([parentDelegate respondsToSelector:onCompleteCallback]) {
[parentDelegate performSelector:onCompleteCallback withObject:self];
}
if ([self respondsToSelector:#selector(receivedItems:)])
[self receivedItems:items];
else
SHOW_ALERT(#"parserDidEndDocument:", #"receivedItems: not responding!", nil, #"Okay", nil)
}
#pragma mark -
#pragma mark Setters / Getters
- (id)delegate {
return self;
}
- (void)setDelegate:(id)new_delegate {
_delegate = self;
}
- (BOOL)isSuccessful {
return success;
}
- (BOOL)isLoading {
return loading;
}
- (BOOL)isParsed {
return parsed;
}
- (NSArray *)getCategories {
return categories;
}
- (NSDictionary *)getRoot {
return root;
}
- (void)dealloc {
[super dealloc];
}

Related

how to fetch data from xml parsing

I am trying to parse data from xml parsing but it could not show anything ..
-(void)viewDidLoad {
[super viewDidLoad];
self.mdata=[[NSMutableData alloc]init];
marr=[[NSMutableArray alloc]init];
mwebcall =[[NSMutableArray alloc]init];
NSString *urlstr=#"http://www.espncricinfo.com/rss/content/story/feeds/6.xml";
NSURL *url1 = [NSURL URLWithString:urlstr];
NSURLRequest *urlrequest=[[NSURLRequest alloc]initWithURL:url1 ];
con = [[NSURLConnection alloc]initWithRequest:urlrequest delegate:self];
[con start];
}
// Do any additional setup after loading the view, typically from a nib.
//#pragma mark-xmlmethods
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[mdata appendData:data];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.xmlparse=[[NSXMLParser alloc]initWithData:mdata];
self.xmlparse .delegate=self ;
[self.xmlparse parse];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"%#",error);
}
-(void)parserDidStartDocument:(NSXMLParser *)parser{
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"item"])
{
str=#"item";
}
else if ([elementName isEqualToString:#"title"])
{
str=#"title";
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([str isEqualToString:#"item"])
{
str1=#"";
str1=[str1 stringByAppendingString:string];`enter code here`
}
if ([str isEqualToString:#"title"])
{
str1=#"";
str1=[str1 stringByAppendingString:string];
NSLog(#"%#",str1);
}`enter code here`
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([str isEqualToString:#"item"])
{
[mwebcall addObject:str1];
NSLog(#"%#",str1);
}
if ([str isEqualToString:#"title"])
{
[mwebcall addObject:str1];
NSLog(#"%#",str1);
}
}
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
}
Use this GitHub library.
OR
NSString *url=#"http://www.lancers.jp/work";
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
NSDictionary *dict=[XMLParser dictionaryForXMLData:data error:nil];
NSLog(#"%#",[dict description]);
Use this code and create the following files
XMLParser.h
#import <Foundation/Foundation.h>
#interface XMLParser : NSObject<NSXMLParserDelegate>
{
NSMutableArray *dictionaryStack;
NSMutableString *textInProgress;
NSError **errorPointer;
}
+ (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)errorPointer;
+ (NSDictionary *)dictionaryForXMLString:(NSString *)string error:(NSError **)errorPointer;
#end
XMLParser.m
#import "XMLParser.h"
NSString *const kXMLReaderTextNodeKey = #"text";
#interface XMLParser (Internal)
- (id)initWithError:(NSError **)error;
- (NSDictionary *)objectWithData:(NSData *)data;
#end
#implementation XMLParser
#pragma mark -
#pragma mark Public methods
+ (NSDictionary *)dictionaryForXMLData:(NSData *)data error:(NSError **)error
{
XMLParser *reader = [[XMLParser alloc] initWithError:error];
NSDictionary *rootDictionary = [reader objectWithData:data];
[reader release];
return rootDictionary;
}
+ (NSDictionary *)dictionaryForXMLString:(NSString *)string error:(NSError **)error
{
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
return [XMLParser dictionaryForXMLData:data error:error];
}
#pragma mark -
#pragma mark Parsing
- (id)initWithError:(NSError **)error
{
if (self = [super init])
{
errorPointer = error;
}
return self;
}
- (void)dealloc
{
[dictionaryStack release];
[textInProgress release];
[super dealloc];
}
- (NSDictionary *)objectWithData:(NSData *)data
{
// Clear out any old data
[dictionaryStack release];
[textInProgress release];
dictionaryStack = [[NSMutableArray alloc] init];
textInProgress = [[NSMutableString alloc] init];
// Initialize the stack with a fresh dictionary
[dictionaryStack addObject:[NSMutableDictionary dictionary]];
// Parse the XML
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
BOOL success = [parser parse];
// Return the stack's root dictionary on success
if (success)
{
NSDictionary *resultDict = [dictionaryStack objectAtIndex:0];
return resultDict;
}
return nil;
}
#pragma mark -
#pragma mark NSXMLParserDelegate methods
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
// Get the dictionary for the current level in the stack
NSMutableDictionary *parentDict = [dictionaryStack lastObject];
// Create the child dictionary for the new element, and initilaize it with the attributes
NSMutableDictionary *childDict = [NSMutableDictionary dictionary];
[childDict addEntriesFromDictionary:attributeDict];
// If there's already an item for this key, it means we need to create an array
id existingValue = [parentDict objectForKey:elementName];
if (existingValue)
{
NSMutableArray *array = nil;
if ([existingValue isKindOfClass:[NSMutableArray class]])
{
// The array exists, so use it
array = (NSMutableArray *) existingValue;
}
else
{
// Create an array if it doesn't exist
array = [NSMutableArray array];
[array addObject:existingValue];
// Replace the child dictionary with an array of children dictionaries
[parentDict setObject:array forKey:elementName];
}
// Add the new child dictionary to the array
[array addObject:childDict];
}
else
{
// No existing value, so update the dictionary
[parentDict setObject:childDict forKey:elementName];
}
// Update the stack
[dictionaryStack addObject:childDict];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
// Update the parent dict with text info
NSMutableDictionary *dictInProgress = [dictionaryStack lastObject];
// Set the text property
if ([textInProgress length] > 0)
{
[dictInProgress setObject:textInProgress forKey:kXMLReaderTextNodeKey];
// Reset the text
[textInProgress release];
textInProgress = [[NSMutableString alloc] init];
}
// Pop the current dict
[dictionaryStack removeLastObject];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
// Build the text value
[textInProgress appendString:string];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
// Set the error pointer to the parser's error object
*errorPointer = parseError;
}
#end

How to display XML parsed data in UILabel

I am trying to display the data parsed from an XML file from the web to a UILabel called profilesLabel.
I'm trying to display all the lastName's in the label, but the value is set to the email address for some reason. Can someone help me understand why as I'm new to objective-c
here is the code:
-(id)loadXMLByURL:(NSString *)urlString
{
profile = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"email"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"address"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile->firstName = currentNodeContent;
NSLog(#"%#",currentProfile->firstName);
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"email"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"address"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"profiles"])
{
[self->profile addObject:currentProfile];
currentProfile = nil;
currentNodeContent = nil;
}
}
- (IBAction)bringFont:(id)sender
{
//Here is a button that should show the parsed data in profilesLabel when pressed
profilesLabel.text = currentProfile->lastName; //Shows email address for some reason
//What I want is to show every single profile in profilesLabel underneath each other
}
- (void)viewDidLoad
{
[profilesScrolView setScrollEnabled:YES];
[profilesScrolView setContentSize:CGSizeMake(680, 1200)];
[super viewDidLoad];
xmlParser = [[ViewController alloc] loadXMLByURL:#"http://dierenpensionlindehof.nl/XML_File.xml"];
}
Any help would be appreciated, Tahnks!
is the issue that here:
if([elementName isEqualToString:#"profiles"])
{
[self->profile addObject:currentProfile];
currentProfile = nil;
currentNodeContent = nil;
}
you are setting currentProfile to nil
and then using currentProfile here:
- (IBAction)bringFont:(id)sender
{
//Here is a button that should show the parsed data in profilesLabel when pressed
profilesLabel.text = currentProfile->lastName;
EDIT:
After clarification that the issue was wanting to know how to display different data.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
...
// At the end of each loop add current profile to the mutable array
[profile addObject:currentProfile];
// Now you can set currentProfile to nil
currentProfile = nil;
}
- (IBAction)bringFont:(id)sender
{
// If you want to display all of this data I would recommend creating a
// UITableView and have each entry as a row's title. But thats another
// issue so to set them all into the label as you asked:
// Loop through the array and add the strings together adding a newline each time
NSMutableString *str = [[NSMutableString alloc] init];
for(NSObject *obj in profile)
{
// Obj will need to be casted to whatever type 'currentProfile' is
[str appendFormat:#"\n %#", obj->lastName];
}
// Compute what height the UILabel needs to be to display this string
CGSize expectedSize = [str sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:NSLineBreakByWordWrapping];
CGRect newFrame = CGRectMake(0, 0, expectedSize.width, expectedSize.height);
[profilesLabel setFrame:newFrame];
[profilesLabel setText:str];
}
EDIT 2:
After yet more clarification that the issue is that you don't have the last names, please draw your attention to the fact that you are assigning everything to lastName in this function:
if([elementName isEqualToString:#"lastname"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"email"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"address"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
in every section you use: currentProfile->lastName = currentNodeContent; you need to set the other values inside currentProfile !!!

parsed feed not visible on UITableView, cellForRowAtIndexPath method not getting accessed

I am trying to show parsed Yahoo RSS feed on the table view. But nothing is getting shown on the screen. When I used breakpoints I came to know that the control is not going to cellForRowAtIndexPath method at all. I don't know why that is happening. The structure of the yahoo feed is as follows:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Yahoo! News - Latest News & Headlines</title>
<link>http://news.yahoo.com/</link>
<description>The latest news and headlines from Yahoo! News. Get breaking news stories and in-depth coverage with videos and photos.</description>
<language>en-US</language>
<copyright>Copyright (c) 2013 Yahoo! Inc. All rights reserved</copyright>
<pubDate>Sun, 21 Apr 2013 17:08:00 -0400</pubDate>
<ttl>5</ttl>
<image>
<title>Yahoo! News - Latest News & Headlines</title>
<link>http://news.yahoo.com/</link>
<url>http://l.yimg.com/a/i/us/nws/th/main_142c.gif</url>
</image>
<item><title>After the bombings, the blame game begins</title><description><p><a href="http://news.yahoo.com/boston-marathon-bombing-blame-game-begins-210800101.html"><img src="http://l3.yimg.com/bt/api/res/1.2/uiv31afw5K_BzPxeYQz44Q--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2013-04-22T013026Z_741208741_GM1E94M0Q7101_RTRMADP_3_USA-EXPLOSIONS-BOSTON.JPG" width="130" height="86" alt="A couple embraces at a memorial on Boylston Street to the victims of the Boston Marathon bombings in Boston" align="left" title="A couple embraces at a memorial on Boylston Street to the victims of the Boston Marathon bombings in Boston" border="0" /></a>Some lawmakers fault the FBI for not following up on intelligence about one of the alleged bombers.</p><br clear="all"/></description><link>http://news.yahoo.com/boston-marathon-bombing-blame-game-begins-210800101.html</link><pubDate>Sun, 21 Apr 2013 17:08:00 -0400</pubDate><source url="http://www.csmonitor.com/">Christian Science Monitor</source><guid isPermaLink="false">boston-marathon-bombing-blame-game-begins-210800101</guid><media:content url="http://l3.yimg.com/bt/api/res/1.2/uiv31afw5K_BzPxeYQz44Q--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2013-04-22T013026Z_741208741_GM1E94M0Q7101_RTRMADP_3_USA-EXPLOSIONS-BOSTON.JPG" type="image/jpeg" width="130" height="86"></media:content><media:text type="html"><p><a href="http://news.yahoo.com/boston-marathon-bombing-blame-game-begins-210800101.html"><img src="http://l3.yimg.com/bt/api/res/1.2/uiv31afw5K_BzPxeYQz44Q--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2013-04-22T013026Z_741208741_GM1E94M0Q7101_RTRMADP_3_USA-EXPLOSIONS-BOSTON.JPG" width="130" height="86" alt="A couple embraces at a memorial on Boylston Street to the victims of the Boston Marathon bombings in Boston" align="left" title="A couple embraces at a memorial on Boylston Street to the victims of the Boston Marathon bombings in Boston" border="0" /></a>Some lawmakers fault the FBI for not following up on intelligence about one of the alleged bombers.</p><br clear="all"/></media:text><media:credit role="publishing company"></media:credit></item></guid></channel>
</rss>
My feedViewController.m is as follows:
#interface feedViewController ()
#end
#implementation feedViewController
#synthesize tableView,showPosts;
//#synthesize feed;
Feed *xmlParseFeed;
//channel *chShow;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//self.feed = [[Feed alloc] init];
self.showPosts = [[NSMutableArray alloc] init];
NSArray *newPosts = [xmlParseFeed newPosts];
if (newPosts) {
[self.showPosts addObjectsFromArray:newPosts];
//[newPosts release];
}
static NSString *feedURLString = #"http://news.yahoo.com/rss";
NSURL *feedURL = [NSURL URLWithString:feedURLString];
xmlParseFeed = [[Feed alloc] initWithURL:feedURL];
self.showPosts = [[NSMutableArray alloc] init];
[xmlParseFeed refresh];
}
- (void)viewDidUnload
{
[self setTableView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [showPosts count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
ItemDataCollection *post = [showPosts objectAtIndex:indexPath.row];
Feed *entry = [showPosts objectAtIndex:indexPath.row];
// Set up the cell...
channel *channelRecord = [self.showPosts objectAtIndex:indexPath.row];
cell.textLabel.text = channelRecord.cTitle;
cell.textLabel.text = channelRecord.pubDate;
NSLog(#"channelRecord.title *****************%#",channelRecord.cTitle);
/* cell.textLabel.text = post.title;
cell.textLabel.text = post.itemDescription;
cell.textLabel.text = post.titleImage;
NSLog(#"item title******%#",post.title); */
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:12];
cell.textLabel.numberOfLines = 1;
return cell;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Properties in channel class are: cTitle,pubDate and itemCollectionArray. Properties in Post class are: title, itemDescription and titleImage. Feed class is for parsing. the contents of Feed.m is as follows:
#class ItemDataCollection;
#implementation Feed
#synthesize feedURL,feedRequest,currentElement,currentElementData;
//#synthesize feedChannel;
//#synthesize feedPosts;
static ItemDataCollection *itemCollection;
static NSMutableArray *channelCollection;
NSMutableString *mString;
NSMutableString *str;
channel *Channel ;
- (NSArray *)newPosts {
NSMutableArray *posts = [[NSMutableArray alloc] init];
for (NSInteger item = 1; item <= 5; item++) {
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ItemDataCollection *newPost;
newPost = [[ItemDataCollection alloc] init];
// NSString *pubDate = [NSDate dateWithTimeIntervalSinceNow:#"pubDate"];
newPost.title = [NSString stringWithFormat:#"title %#", kTitleElementName];
newPost.itemDescription = [NSString stringWithFormat:#"itemdescription %#", kItemDescription];
newPost.titleImage = [NSString stringWithFormat:#"image %#",kItemImage];
// newPost.itemTitle = [NSString stringWithFormat:#"itemtitle %#", ITEM_TITLE_XML];
[posts addObject:newPost];
//[newPost release];
// [pool drain];
}
return posts;
}
- (Feed *) initXMLParser {
//[super init];
appDelegate = (appAppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
-(id)initWithURL:(NSURL *)sourceURL {
if (self = [super init]) {
self.feedURL = sourceURL;
channelCollection=[[NSMutableArray alloc] init];
}
return self;
}
- (void)refresh {
self.feedRequest = [ASIHTTPRequest requestWithURL:feedURL];
// [feedPosts removeAllObjects];
[feedRequest setDelegate:self];
[feedRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
NSData *responseData = [request responseData];
// NSLog(#"*************response are *********%#",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];
[parser setDelegate:self];
if ([parser parse]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:#"myevent"
object:nil];
// [posts ]
}
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(#"requestFailed: %#", [error localizedDescription]);
}
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:kChannelElementName]) {
Channel = [[channel alloc] init];
dict=[[NSMutableDictionary alloc] init];
[Channel setItemCollectionArray:[[NSMutableArray alloc] init]];
return ;
}
if ([elementName isEqualToString:kItemElementName]) {
itemCollection=[[ItemDataCollection alloc] init];
return ;
}
if ([elementName isEqualToString:kTitleElementName]) {
return ;
}
if([elementName isEqualToString:kItemDescription]){
return ;
}
if ([elementName isEqualToString:kItemImage]) {
NSString *urlString = attributeDict[#"url"];
if(urlString){
[dict setObject:urlString forKey:#"img"];
NSLog(#"%#",urlString);
mString = [NSString stringWithFormat:urlString];
str = [NSString stringWithFormat:mString];
}
return ;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (currentElementData == nil) {
self.currentElementData = [[NSMutableString alloc] init];
}
[currentElementData appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:kChannelElementName]) {
[channelCollection addObject:Channel];
NSLog(#"channel are***********%#",channelCollection);
for(ItemDataCollection *mydata in Channel.itemCollectionArray){
NSLog(#"___%# <><><><><> desc \n <><><><><><> img \n %#",mydata.title,/*mydata.itemDescription*/mydata.titleImage);
}
Channel =nil;
}
else if ([elementName isEqualToString:kItemElementName]) {
[[Channel itemCollectionArray] addObject:itemCollection];
itemCollection=nil;
}
else if ([elementName isEqualToString:kTitleElementName]) {
if(itemCollection==nil){
Channel.cTitle=currentElementData;
}
else{
itemCollection.title=currentElementData;
}
}
else if ([elementName isEqualToString:kPubDate]) {
Channel.pubDate=currentElementData;
}
else if ([elementName isEqualToString: kItemDescription]) {
if(itemCollection!=nil){
itemCollection.itemDescription = currentElementData;
}
}
else if([currentElementData rangeOfString:#"media:content"].location){
if(itemCollection!=nil){
if([str isEqualToString:mString]){
// [currentElementData appendString:dict];
itemCollection.titleImage = mString;
} else{
itemCollection.titleImage = #"";
}
}
}
self.currentElementData = nil;
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString *info = [NSString stringWithFormat:
#"Error %i, Description: %#, Line: %i, Column: %i",
[parseError code],
[[parser parserError] localizedDescription],
[parser lineNumber],
[parser columnNumber]];
NSLog(#"RSS Feed Parse Error: %#", info);
}
#end
The feed is getting parsed and can be seen on the console. But it is not visible on the screen. What can be the reason? As i said earlier, cellForRowAtIndexPath() is not getting accessed at all. What's the reason for that??
I've added this method:
- (void)feedChanged:(NSNotification *)notification {
NSArray *newPosts = [xmlParseFeed newPosts];
NSLog(#"%#",newPosts);
if (newPosts) {
[self.showPosts addObjectsFromArray:newPosts];
[self.tableView reloadData];
// [self updateViewTitle];
// [newPosts release];
}
I don't see where in your code you're calling reloadData from UITableView. You need to call this method after you load newPosts.
If this doesn't work, check a couple of things like:
What is the value returned by tableView:numberOfRowsInSection:? Is it greater than zero? If it's zero, that's why tableView:cellForRowAtIndexPath doesn't get called.
How do you load your feed? Is it in the main thread or different thread? You should be loading it in a different thread, so you won't block your UI while you load the data, but make sure you're calling reloadData after the data is loaded into newPosts.

empty tableview rows when parsing with NSXMLPaerser using ASIHTTPRequest

I'm pretty new iPhone development and i have a problem.
After several hours of searching and digging in the code I could understand the source of the problem (hope) but do not know how to solve it.
the problem is that the tableView cells loads before the parser is finish so the "[array count]" is nil.
When I set the 'number of rows in section' manually, the table does appear, but only after a few sec and scrolling up and down.
i have 2 classes, one for XMLParser and one for show the tableView.
According to what I read before I opened this question is that i need to reload the tavleview data but becuase i have 2 various classes i dont know how to do that.
any ideas?
Thanks in davance!
here is my XMLParser code:
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
self.titles = [[NSMutableArray alloc]init];
self.descriptions = [[NSMutableArray alloc]init];
self.links = [[NSMutableArray alloc]init];
self.pubDate = [[NSMutableArray alloc]init];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
}
BOOL isItem = NO;
BOOL isTitle = NO;
BOOL isDesription = NO;
BOOL isImg = NO;
BOOL isPubDate = NO;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"item"]) {
isItem = YES;
}
if ([elementName isEqualToString:#"title"]) {
isTitle=YES;
self.titlesString = [[NSMutableString alloc]init];
}
if ([elementName isEqualToString:#"description"]) {
isDesription = YES;
self.descriptionString = [[NSMutableString alloc]init];;
self.data = [NSMutableData data];
}
if ([elementName isEqualToString:#"pubDate"]) {
isPubDate = YES;
self.pubDateString = [[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(isItem && isTitle){
[self.titlesString appendString:string];
}
if (isItem && isDesription) {
[self.descriptionString appendString:string];
}
if (isItem && isPubDate) {
[self.pubDateString appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{
if (self.data)
[self.data appendData:CDATABlock];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"item"]) {
isItem = NO;
[self.titles addObject:self.titlesString];
[self.descriptions addObject:self.descriptionString];
[self.pubDate addObject:self.pubDateString];
NSLog(#"%#,%#,%#,",self.titlesString,self.descriptionString,self.pubDate);
}
if ([elementName isEqualToString:#"title"]) {
isTitle=NO;
}
if ([elementName isEqualToString:#"description"]) {
isDesription = NO;
if ([self.data length] > 0)
{
NSString *htmlSnippet = [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding];
NSString *imageSrc = [self firstImgUrlString:htmlSnippet];
[self.links addObject:imageSrc];
}
self.data = nil;
}
if([elementName isEqualToString:#"pubDate"])
isPubDate = NO;
}
- (NSString *)firstImgUrlString:(NSString *)string
{
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:#"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *result = [regex firstMatchInString:string
options:0
range:NSMakeRange(0, [string length])];
if (result)
return [string substringWithRange:[result rangeAtIndex:2]];
return nil;
}
and here's my show tableView code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"menuButton.png"] style:UIBarButtonItemStyleBordered target:self.viewDeckController action:#selector(toggleLeftView)];
NSURL *url;
if (!self.isGetLink)
url = [NSURL URLWithString:#"http://www.ynet.co.il/Integration/StoryRss2.xml"];
else
url = [NSURL URLWithString:self.linkForParsingString];
if (!self.xmlParser) {
self.xmlParser = [[XMLparser alloc]init];
[self.xmlParser LoadXMLWithURl:url];
}
self.isGetLink = NO;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.xmlParser.titles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.lblTitle.text = [self.xmlParser.titles objectAtIndex:indexPath.row];
cell.lblTitle.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[self.xmlParser.links objectAtIndex:indexPath.row]]];
cell.imgView.image = [UIImage imageWithData:data];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 82;
}
#pragma mark - Table view delegate
NSString *curnentDes;
NSString *currentTitle;
NSString *currentPubDate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ReadViewController *rvc = [[ReadViewController alloc]initWithNibName:#"ReadViewController" bundle:nil];
curnentDes = [self.xmlParser.descriptions objectAtIndex:indexPath.row];
currentTitle = [self.xmlParser.titles objectAtIndex:indexPath.row];
currentPubDate = [self.xmlParser.pubDate objectAtIndex:indexPath.row];
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc]init];
[inputFormatter setDateFormat:#"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *inputDate = [inputFormatter dateFromString:currentPubDate];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
[outputFormatter setDateFormat:#"dd/MM/yyyy HH:mm"];
NSString *outputDate = [outputFormatter stringFromDate:inputDate];
rvc.description = curnentDes;
rvc.stitle = currentTitle;
rvc.pubDate = outputDate;
[self.navigationController pushViewController:rvc animated:YES];
}
Pretty simple reload the table after your parsing is done, you are good to go. The reason your data comes after scrolling is your array is updated at a later point and then cellForRowAtIndex is called and array has content so you see rows.
Note: cellForRow is called for every row (hope you know that).
Using notification:
In your parser class
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[[NSNotificationCenter defaultCenter ]postNotificationName:#"parsingComplete" object:nil];
}
In ViewDidLoad of your table view class add this code and add the other functions anywhere in ur class:
your viewDidLoad(edited)
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(parsingComplete) name:#"parsingComplete" object:nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"menuButton.png"] style:UIBarButtonItemStyleBordered target:self.viewDeckController action:#selector(toggleLeftView)];
NSURL *url;
if (!self.isGetLink)
url = [NSURL URLWithString:#"http://www.ynet.co.il/Integration/StoryRss2.xml"];
else
url = [NSURL URLWithString:self.linkForParsingString];
if (!self.xmlParser) {
self.xmlParser = [[XMLparser alloc]init];
[self.xmlParser LoadXMLWithURl:url];
}
self.isGetLink = NO;
}
//Function to handle notification:
-(void)parsingComplete
{
NSLog(#"parsing results: %#",self.xmlParser.titles);
//change your tableViewName
[yourTableView reloadData];
}
//removing notification:
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Reload the table once parsing is completed. Use delegate methods to reload the table view from didEndElement method. Try some think like this.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"Final Element"])
{
// Reload your table View using delegates
}
}

Youtube thumbnail from channel rss feed?

I am trying to load a youtube channel's feed into a uitableview with an rss feed. I need this to display the thumbnail from the individual videos. I can only find this using the gdata client which does not work. Here is the code I have so far:
Videos.h:
#import <UIKit/UIKit.h>
#interface Videos : UITableViewController<NSXMLParserelegate>{
IBOutlet UITableView * newsTable;
UIActivityIndicatorView * activityIndicator;
CGSize cellSize;
NSXMLParser * rssParser;
NSMutableArray * stories;
// a temporary item; added to the "stories" array one at a time, and cleared for the next one
NSMutableDictionary * item;
// it parses through the document, from top to bottom...
// we collect and cache each sub-element value, and then save each item to our array.
// we use these to track each current item, until it's ready to be added to the "stories" array
NSString * currentElement;
NSMutableString * currentTitle, * currentDate, * currentSummary, * currentLink;
}
- (void)parseXMLFileAtURL:(NSString *)URL;
#end
Videos.m
#import "Videos.h"
#import "AppDelegate.h"
#implementation Videos
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.tabBarItem.image = [UIImage imageNamed:#"clapboard#2x.png"];
}
return self;
}
- (void)viewDidLoad {
// Add the following line if you want the list to be editable
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [stories count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
cell.textLabel.text=[[stories objectAtIndex: storyIndex] objectForKey: #"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: #"link"];
NSLog(#"%#",stories );
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#"\n" withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
// open in Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([stories count] == 0) {
NSString * path = #"https://youtube.com/rss/user/TheGruenebergBrother/videos.rss";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}
- (void)viewWillDisappear:(BOOL)animated {
}
- (void)viewDidDisappear:(BOOL)animated {
}
#pragma mark - parseing_Delegate_methods
- (void)parserDidStartDocument:(NSXMLParser *)parser{
NSLog(#"found file and started parsing");
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
//you must then convert the path to a proper NSURL or it won't work
NSURL *xmlURL = [NSURL URLWithString:URL];
// here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
// this may be necessary only for the toolchain
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[rssParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString * errorString = [NSString stringWithFormat:#"Unable to download story feed from web site (Error code %i )", [parseError code]];
NSLog(#"error parsing XML: %#", errorString);
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Error loading content" message:errorString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(#"found this element: %#", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:#"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(#"ended element: %#", elementName);
if ([elementName isEqualToString:#"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:#"title"];
[item setObject:currentLink forKey:#"link"];
[item setObject:currentSummary forKey:#"summary"];
[item setObject:currentDate forKey:#"date"];
[stories addObject:[item copy]];
NSLog(#"adding story: %#", currentTitle);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(#"found characters: %#", string);
// save the characters for the current item...
if ([currentElement isEqualToString:#"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:#"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:#"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:#"pubDate"]) {
[currentDate appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
NSLog(#"all done!");
NSLog(#"stories array has %d items", [stories count]);
[newsTable reloadData];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[currentElement release];
[rssParser release];
[stories release];
[item release];
[currentTitle release];
[currentDate release];
[currentSummary release];
[currentLink release];
[super dealloc];
}
#end
Also where should the code go, and what is the code?
Thanks
there is a thumbnail url,
http://img.youtube.com/vi/VIDEOIDHERE/0.jpg
http://img.youtube.com/vi/VIDEOIDHERE/1.jpg
http://img.youtube.com/vi/VIDEOIDHERE/2.jpg
http://img.youtube.com/vi/VIDEOIDHERE/3.jpg
will fetch you the thumbnail for any video. The number represents the quality, zero being the highest. E.g:
http://img.youtube.com/vi/F2Jko4Ipdrs/0.jpg

Resources