07-31-2010, 04:17 PM
#1 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
Feed not showing in the table
My rss feed is not showing in the UITableView. Here is my code please tell me if you can see a problem
Code:
//
// theLatest.m
// TabBar
//
// Created by Max on 01/08/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "theLatest.h"
#import "DetailViewController.h"
@implementation theLatest
- (void)viewDidLoad {
// Add the following line if you want the list to be editable
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (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] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[cell setText:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
cell.textLabel.textColor = [UIColor redColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
-(IBAction)back{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:[self view]
cache:YES];
[detailView removeFromSuperview];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem = nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
/*[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:[self view]
cache:YES];
[[self view] addSubview:detailView];
[UIView commitAnimations];
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"Back", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(back)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;*/
//NSLog(@"link: %@", storyLink);
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
DetailViewController *viewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
//DetailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
viewController.selectedCountry = storyLink;
//[viewController.myWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]]];
[self.navigationController pushViewController:viewController animated:YES];
//[self.DetailViewController.myWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]]];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([stories count] == 0) {
NSString * path = @"http://lawandorderinrussia.org/feed";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([rssTable bounds].size.width, 60);
}
- (void)viewWillDisappear:(BOOL)animated {
}
- (void)viewDidDisappear:(BOOL)animated {
}
- (void)parserDidStartDocument:(NSXMLParser *)parser{
NSLog(@"found file and started parsing");
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[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"]) {
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"]) {
[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{
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]);
[rssTable 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
Last edited by iSDK; 08-01-2010 at 03:01 PM .
07-31-2010, 06:39 PM
#2 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
BUMP!!!!!!!!
Last edited by iSDK; 08-01-2010 at 01:00 PM .
08-01-2010, 03:01 PM
#3 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
bump
08-01-2010, 04:10 PM
#4 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,896
Might help to post what exactly is going on. Are you getting the expected data but you can't see it or what?
Just a quick skim,
Code:
[cell setText:...];
- Should be
[cell.textLabel setText:...];
08-01-2010, 04:11 PM
#5 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
exactly what you said. I can view the NSLogs in the debugger but the posts are not showing up in the table.
Quote:
Originally Posted by
harrytheshark
Might help to post what exactly is going on. Are you getting the expected data but you can't see it or what?
Just a quick skim,
Code:
[cell setText:...];
- Should be
[cell.textLabel setText:...];
08-01-2010, 04:18 PM
#6 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,896
Any reason you're doing this:
Code:
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
And not:
Code:
int storyIndex = indexPath.row;
And try doing:
Code:
NSLog(@"%@", stories);
In your parserDidEndDocument.
08-01-2010, 04:20 PM
#7 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
im not sure, il give your replies a go thank you
Quote:
Originally Posted by
harrytheshark
Any reason you're doing this:
Code:
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
And not:
Code:
int storyIndex = indexPath.row;
And try doing:
Code:
NSLog(@"%@", stories);
In your parserDidEndDocument.
08-01-2010, 04:29 PM
#8 (permalink )
Indie Developer
Join Date: Jul 2010
Posts: 1,346
its still not showing up, here is the nslog :
Code:
2010-08-01 22:24:31.272 Hermitage[1270:307] (
{
date = "Fri, 23 Jul 2010 09:23:15 +0000\n\t\t";
link = "http://feedproxy.google.com/~r/Hermitage_Story/~3/bhjTCN4a4Kg/\n\t\t";
summary = "International Legal Alliance Calls upon Russian President to Prosecute Officials Involved in Sergei Magnitsky\U2019s Torture and Murder in Custody; Issues Strong Warning about Deterrent to Inward Investment and Risk to Safety of Employees in Russia\n23 July 2010 – 7,7000 lawyers from 147 law firms from 81 countries have appealed to Russian President Medvedev, himself [...]<img src=\"http://feeds.feedburner.com/~r/Hermitage_Story/~4/bhjTCN4a4Kg\" height=\"1\" width=\"1\"/>\n\t\t";
title = "International Legal Alliance Calls upon Russian President to Prosecute Officials Involved in Sergei Magnitsky\U2019s Torture and Murder in Custody\n\t\t";
},
{
date = "Fri, 23 Jul 2010 09:12:42 +0000\n\t\t";
link = "http://feedproxy.google.com/~r/Hermitage_Story/~3/CTC1KbMK0-Q/\n\t\t";
summary = "\U041c\U0435\U0436\U0434\U0443\U043d\U0430\U0440\U043e\U0434\U043d\U0430\U044f \U0430\U0441\U0441\U043e\U0446\U0438\U0430\U0446\U0438\U044f \U044e\U0440\U0438\U0441\U0442\U043e\U0432 – \U041f\U0440\U0435\U0437\U0438\U0434\U0435\U043d\U0442\U0443 \U041c\U0435\U0434\U0432\U0435\U0434\U0435\U0432\U0443: \U0411\U0435\U0437\U043d\U0430\U043a\U0430\U0437\U0430\U043d\U043d\U043e\U0441\U0442\U044c \U0441\U043e\U0442\U0440\U0443\U0434\U043d\U0438\U043a\U043e\U0432 \U041c\U0412\U0414, \U043e\U0442\U0432\U0435\U0442\U0441\U0442\U0432\U0435\U043d\U043d\U044b\U0445 \U0437\U0430 \U0433\U0438\U0431\U0435\U043b\U044c \U0421\U0435\U0440\U0433\U0435\U044f \U041c\U0430\U0433\U043d\U0438\U0442\U0441\U043a\U043e\U0433\U043e, \U0443\U0433\U0440\U043e\U0436\U0430\U0435\U0442 \U0431\U0435\U0437\U043e\U043f\U0430\U0441\U043d\U043e\U0441\U0442\U0438 \U043b\U044e\U0434\U0435\U0439 \U0438 \U043f\U0440\U0435\U043f\U044f\U0442\U0441\U0442\U0432\U0443\U0435\U0442 \U0438\U043d\U0432\U0435\U0441\U0442\U0438\U0446\U0438\U044f\U043c \n23 \U0438\U044e\U043b\U044f 2010 \U0433. \U2013 \U041c\U0435\U0436\U0434\U0443\U043d\U0430\U0440\U043e\U0434\U043d\U0430\U044f \U0430\U0441\U0441\U043e\U0446\U0438\U0430\U0446\U0438\U044f \U044e\U0440\U0438\U0441\U0442\U043e\U0432 \U0422AGLaw, \U043e\U0431\U044a\U0435\U0434\U0438\U043d\U044f\U044e\U0449\U0430\U044f 7 700 \U044e\U0440\U0438\U0441\U0442\U043e\U0432 \U0438\U0437 147 \U0444\U0438\U0440\U043c, \U043f\U0440\U0435\U0434\U0441\U0442\U0430\U0432\U043b\U044f\U044e\U0449\U0438\U0445 81 \U0441\U0442\U0440\U0430\U043d\U0443, \U043f\U0440\U0438\U0437\U0432\U0430\U043b\U0430 \U041f\U0440\U0435\U0437\U0438\U0434\U0435\U043d\U0442\U0430 \U0420\U043e\U0441\U0441\U0438\U0438 \U0414\U043c\U0438\U0442\U0440\U0438\U044f \U041c\U0435\U0434\U0432\U0435\U0434\U0435\U0432\U0430, \U0441\U0430\U043c\U043e\U0433\U043e \U043f\U0440\U043e\U0444\U0435\U0441\U0441\U0438\U043e\U043d\U0430\U043b\U044c\U043d\U043e\U0433\U043e \U044e\U0440\U0438\U0441\U0442\U0430, \U043f\U0440\U0438\U0432\U043b\U0435\U0447\U044c \U043a \U043e\U0442\U0432\U0435\U0442\U0443 \U0447\U0438\U043d\U043e\U0432\U043d\U0438\U043a\U043e\U0432, \U043f\U0440\U0438\U0447\U0430\U0441\U0442\U043d\U044b\U0445 \U043a \U043d\U0435\U0437\U0430\U043a\U043e\U043d\U043d\U043e\U043c\U0443 \U0430\U0440\U0435\U0441\U0442\U0443 [...]<img src=\"http://feeds.feedburner.com/~r/Hermitage_Story/~4/CTC1KbMK0-Q\" height=\"1\" width=\"1\"/>\n\t\t";
title = "\U041c\U0435\U0436\U0434\U0443\U043d\U0430\U0440\U043e\U0434\U043d\U0430\U044f \U0430\U0441\U0441\U043e\U0446\U0438\U0430\U0446\U0438\U044f \U044e\U0440\U0438\U0441\U0442\U043e\U0432 \U2013 \U041f\U0440\U0435\U0437\U0438\U0434\U0435\U043d\U0442\U0443 \U041c\U0435\U0434\U0432\U0435\U0434\U0435\U0432\U0443: \U0411\U0435\U0437\U043d\U0430\U043a\U0430\U0437\U0430\U043d\U043d\U043e\U0441\U0442\U044c \U0441\U043e\U0442\U0440\U0443\U0434\U043d\U0438\U043a\U043e\U0432 \U041c\U0412\U0414, \U043e\U0442\U0432\U0435\U0442\U0441\U0442\U0432\U0435\U043d\U043d\U044b\U0445 \U0437\U0430 \U0433\U0438\U0431\U0435\U043b\U044c \U041c\U0430\U0433\U043d\U0438\U0442\U0441\U043a\U043e\U0433\U043e, \U0443\U0433\U0440\U043e\U0436\U0430\U0435\U0442 \U0420\U043e\U0441\U0441\U0438\U0438\n\t\t";
},
Quote:
Originally Posted by
iSDK
im not sure, il give your replies a go thank you
08-01-2010, 09:39 PM
#9 (permalink )
Registered Member
Join Date: Dec 2008
Location: UK
Posts: 1,896
Put in some NSLogs in your cellForRowAtIndex path, and see if the reloadData method is getting called.
Try self.tableView instead of rssTable in your reloadData call.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 352
9 members and 343 guests
alexP , gordo26 , headkaze , mistergreen2011 , nobstudio , Objective Zero , rayjeong , revg , Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs