I am developing an app that shows feeds from multiple websites in a tableview where the user can add additional feeds.
I created the app based on the following tutorial using ASIHTTPRequest.
So, my problem is that after I add a new link, after the refresh method i get duplicate posts from all sources.
Here's my viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =@"Lajmet";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.allEntries = [NSMutableArray array];
self.queue = [[NSOperationQueue alloc] init];
self.feeds = [NSMutableArray arrayWithObjects:@"http://pcworld.al/feed",@"http://geek.com/feed", @"http://feeds.feedburner.com/Mobilecrunch",@"http://zeri.info/rss/rss-5.xml",
nil];
[self.tableView reloadData];
[self refresh];
}
The refresh methods looks like this:
-(void)refresh
{
for (NSString *feed in _feeds)
{
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}
}
In this screenshot you can see how the application looks like and how the add screen works for new sources. I configured the done button so that it adds automatically one feed to test if it works.
-(void)addSourcesViewController:(AddSourcesViewController *)controller didAddSource:(RSSEntry *)source
{
Source *newSource = [[Source alloc] init];
newSource.name = @"Test";
newSource.link = @"http://lajmeshqip.com/feed";
[self.feeds addObject:newSource.link];
NSLog(@"%@", self.feeds);
[self dismissViewControllerAnimated:YES completion:nil];
[self refresh];
}
So my problem is that after hitting the done button, all entries are duplicated and they are shown in the tableview. I tried to use [self.tableView reloadData];
instead of [self refresh];
in the last method but then the new link doesn't appear at all.
Is there a way to load the last entry using ASIHTTPRequest or any tip i can follow? I am new and don't know which approach to follow. Any help would be greatly appreciated.
Thanks a lot!
Granit
I assume the cellRows are created from self.allEntries. So if you add a new Source to your self.feeds, before you download clean your self.allEntries array [self.allEntries removeAllObjects];
because in your refresh method you are already reloading all feeds. After finishing the downloads reload your tableview data.