Objective-C Pull to Refresh - objective-c

I'm trying to implement a pull-to-refresh feature on my RSS feed table. The list pulls normally when loading the app, but I essentially need to replicate that for the pull-down.
Could anyone help as to why the code isn't working?
#import "RSSTableViewController.h"
#import "RSSDetailViewController.h"
#interface RSSTableViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
}
#end
#implementation RSSTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// RSS Settings
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://external.example.co.uk/newpost/example.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull to Refresh"];
[refresh addTarget:self
action:#selector(refreshView:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
}
- (void)refreshView:(UIRefreshControl *)refresh {
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:#"Refreshing news feed..."];
// Refresh Logic
NSURL *url = [NSURL URLWithString:#"http://external.example.co.uk/newpost/example.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
// Set the timestamp
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM d, h:mm a"];
NSString *lastUpdated = [NSString stringWithFormat:#"Last updated: %#",
[formatter stringFromDate:[NSDate date]]];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
[refresh endRefreshing];
[self.tableView reloadData];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[refreshView endRefreshing]; //'Use of undeclared identifier 'refresh view'//
[self.tableView reloadData];
}
- (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;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:#"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc]init];
title = [[NSMutableString alloc]init];
link = [[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
[item setObject:title forKey:#"title"];
[item setObject:link forKey:#"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:#"title"]) {
[title appendString:string];
}
else if ([element isEqualToString:#"link"]) {
[link appendString:string];
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey:#"link"];
[[segue destinationViewController] setUrl:string];
}
}
#end
Anyone got any ideas?

Code works fine
Needed to remove the line in parserDidEndDocument with the error.
I then had to add [feeds removeAllObjects] under the //Refresh Logic line to clear the current table contents.
Thanks guys.

Related

Display Images using RSS Feed in Objective C

I want to display images from the url
RSS Feed
I am using table view controller in my Objective c project..I am able to display text and links perfectly but not able to display images from the Feed url
I am using the following code
**TableViewController.h**
#import <UIKit/UIKit.h>
#interface TableViewController : UITableViewController <NSXMLParserDelegate>
#property (strong, nonatomic) IBOutlet UITableView *TableView;
#end
TableViewController.m
#import "TableViewController.h"
#import "ViewController.h"
#interface TableViewController (){
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
NSString *imageType;
NSString *imageUrl;
}
#end
#implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
feeds=[[NSMutableArray alloc ] init];
NSURL *url = [NSURL URLWithString:#"https://www.nasa.gov/rss/dyn/breaking_news.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:#"title"];
// cell.imageView.image= [[feeds objectAtIndex:indexPath.row] objectForKey:#"title"];
return cell;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
if ([element isEqualToString:#"enclosure"]) {
imageType = [attributeDict objectForKey:#"type"];
imageUrl = [attributeDict objectForKey:#"url"];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
[item setObject:title forKey:#"title"];
[item setObject:link forKey:#"link"];
[item setObject:imageType forKey:#"imageType"];
[item setObject:imageUrl forKey:#"imageUrl"];
[feeds addObject:[item copy]];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:#"title"]) {
[title appendString:string];
} else if ([element isEqualToString:#"link"]) {
[link appendString:string];
}
}
-(void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey:#"link"];
[[segue destinationViewController] setUrl:string];
}
}
#end
Please help me to display images I am stuck with this.Thanks
Use this way :
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"identifier"];
UIImageview imgView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 0, 48, 48)];
imgView.tag = 100;
//ssame way create a label
UILabel titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
titlelabel.tag = 102
[cell.contentview addsubview:imgview];
[cell.contentview addsubview:titlelabel];
}
UIImageview mImgView = (uiimageview *)[cell viewwithtag:100];
UILabel mLabel = (uilabel*)cell viewwithtag:102];
//set data
mlabel = //your label
mimgviw.imge = imageurl
Just put this line to your UITableViewCell
NSString *imgUrl = [[feeds objectAtIndex:indexPath.row] objectForKey:#"imageUrl"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]]];
cell.imageView.image = image;

Search in a NSMutableArray

Hello how I can search in tableView with this?
I use XML parse for NSMutableArray. Gives error when I want to search. I want to make a detailed search for the cell.
http://i.hizliresim.com/blvZQj.png
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
}
// FirstViewController.h
//
//
//
// Copyright (c) 2015 Serkan. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Haber.h"
#interface FirstViewController : UITableViewController<NSXMLParserDelegate,UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchDisplayDelegate>
{
NSXMLParser *parser;
NSMutableArray *haberlistesi;
NSMutableArray *searchArray;
Haber *haber;
__weak IBOutlet UITableView *table;
NSString *currentElement;
}
#property IBOutlet UISearchBar *SearchBar;
#end
//
// FirstViewController.m
//
//
//
// Copyright (c) 2015 Serkan. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize SearchBar;
- (void)viewDidLoad
{
[super viewDidLoad];
haberlistesi = [[NSMutableArray alloc] init];
searchArray = [[NSMutableArray alloc] initWithArray:haberlistesi];
// Hide the search bar until user scrolls up
CGRect newBounds = [[self tableView] bounds];
newBounds.origin.y = newBounds.origin.y + SearchBar.bounds.size.height;
[[self tableView] setBounds:newBounds];
// Initialize the filteredCandyArray with a capacity equal to the candyArray's capacity
// Initialize the refresh control.
self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.backgroundColor = [UIColor purpleColor];
self.refreshControl.tintColor = [UIColor whiteColor];
[self.refreshControl addTarget:self
action:#selector(getXMLData)
forControlEvents:UIControlEventValueChanged];
// Initialize the refresh control.
[self performSelectorInBackground:#selector(getXMLData) withObject:nil];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
// Reload the table
[[self tableView] reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [haberlistesi count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Haber *temp = [haberlistesi objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"mycell"];
NSString *str =[NSString stringWithFormat:#"%#%#",temp.al,temp.sat];
cell.textLabel.text = str;
cell.detailTextLabel.text = temp.baslik;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [UIColor clearColor];
//tableView.backgroundColor = [UIColor clearColor]; //tableview arkakısmını transparan yapar.
//cell.textLabel.text = [searchArray objectAtIndex:indexPath.row];
return cell;
}
-(void)getXMLData
{
NSString *strURL = #"http://www.serkanuyanik.com/eksperlerimiz.xml";
NSURL *url = [NSURL URLWithString:strURL];
NSData *data = [NSData dataWithContentsOfURL:url];
NSLog([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
haberlistesi = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
[self performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = elementName;
if ([elementName isEqualToString:#"record"]) {
haber = [[Haber alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:#"sehir"])
[haber.al appendString:[string stringByReplacingOccurrencesOfString:#"\n" withString:#""]];
if ([currentElement isEqualToString:#"tarih"])
[haber.baslik appendString:[string stringByReplacingOccurrencesOfString:#"\n" withString:#""]];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"record"])
{
[haberlistesi addObject:haber];
}
}
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
[table reloadData];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *address = haber.al;
NSString *mapString = [NSString stringWithFormat:#"http://maps.apple.com/?=%#", address];
NSURL *urlMapScheme = [NSURL URLWithString:mapString];
[[UIApplication sharedApplication] openURL:urlMapScheme];
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)reloadData
{
// Reload table data
[self.tableView reloadData];
// End the refreshing
if (self.refreshControl) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM d, h:mm a"];
NSString *title = [NSString stringWithFormat:#"Son Güncelleme: %#", [formatter stringFromDate:[NSDate date]]];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
forKey:NSForegroundColorAttributeName];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
self.refreshControl.attributedTitle = attributedTitle;
[self.refreshControl endRefreshing];
}
}
#end
You this code for searching :
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSArray * searchResults = [haberlistesi filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: #"al CONTAINS[c] %# OR baslik CONTAINS[c] %#", searchedString, searchedString]];
//Use this searchResults array as DataSource for your table view and reload the table view, For instance:
haberlistesi = [searchResults mutableCopy];
[self.tableView reloadData];
}
Happy Coding..:)

Tableview segue not working?

Yesterday I was working on a project and I came across this error. Kept me up all night! Still no answer that fixes MY ERROR! So what happens is when i tap my cell its not going to next view controller. I made prototype and everything. So before it was giving be a signal sgbart or something and I fixed it with adding this.
This was in -(void)viewDidLoad
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
The error was coming up here -
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Now all that is fixed. Now whenever i go and click a cell its not working.
It is a RSS reader project. Here is the full code.
//
// AppMain.m
// fcffv
//
// Created by Ajay Venkat on 6/09/2014.
// Copyright (c) 2014 AJTech. All rights reserved.
//
#import "AppMain.h"
#import "AppDetail.h"
#interface AppMain () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
}
#end
#implementation AppMain
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad {
[super viewDidLoad];
static NSString *CellIdentifier = #"Cell";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://bountyboulevardss.eq.edu.au/?cat=3&feed=rss2"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: #"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
[item setObject:title forKey:#"title"];
[item setObject:link forKey:#"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:#"title"]) {
[title appendString:string];
} else if ([element isEqualToString:#"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: #"link"];
[[segue destinationViewController] setUrl:string];
}
}
#end
Thank you guys for helping.
By the way I have done all the re search I could do and all leaves me in failure and even more error so please try help me guys.
Also I am new to Objective-C.
Thank you to people who take the time to help me.
This is a project important to a school.
Do you implement didSelectRowatIndex method ? And set delegate ?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
Cheers S.

Adding activity indicator on webview

i m parsing an rss feed and loading in a webview...wat i want is ..to place a custom activity indicator in the exact place..where the parsing begins and the place where the parsing ends....below is the code.
#implementation MenuAndWineListViewController
NSDictionary *dict;
UIAlertView * errorAlert;
- (void)viewDidLoad
{
self.title=#"Menu & WineList";
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
activityIndicator1 = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]autorelease];
activityIndicator1.frame=CGRectMake(0.0,0.0, 40.0, 40.0);
activityIndicator1.center=self.view.center;
[self.view addSubview:activityIndicator1];
NSURL *baseURL=[[NSURL
URLWithString:#"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com /?feedpages&max=0&sort_order=ASC&parent=12&child_of=12"]retain];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if ([stories count] == 0) {
path = #"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com/?feedpages&max=0&
sort_order=ASC&parent=180&child_of=180";
[self parseXMLFileAtURL:path];
}
[menuAndWineListViewController loadHTMLString:[dict objectForKey:#"description"] baseURL:nil];
[menuAndWineListViewController setClipsToBounds:YES];
menuAndWineListViewController.opaque=NO;
menuAndWineListViewController.backgroundColor=[UIColor clearColor];
[menuAndWineListViewController setDelegate:self];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (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 didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = [elementName copy];
if ([elementName isEqualToString:#"item"])
{
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"item"])
{
[item setObject:currentTitle forKey:#"title"];
[item setObject:currentSummary forKey:#"description"];
[stories addObject:[item copy]];
}
for (i=0 ; i<stories.count;i++)
{
dict = [stories objectAtIndex:i];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:#"title"])
{
[currentTitle appendString:string];
}
else if ([currentElement isEqualToString:#"description"])
{
[currentSummary appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[activityIndicator1 stopAnimating];
[activityIndicator1 removeFromSuperview];
NSLog(#"stories array has %d items", [stories count]);
}
I'd put the
[activityIndicator1 startAnimating];
at the beginning of the parseXMLFileAtURL method
and the
[activityIndicator1 stopanimating];
at the beginning of the parserDidEndDocument like you did.

UITable view,images,rssfeeds

how to add an image on the table view header....where the image is read from rss feed and stored in the array called item below is the code
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 69.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* headerView = [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 69.0)];
headerView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: #"1" ofType: #"jpg"]]];
return headerView;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(#"found this element: %#", elementName);
currentElement = [elementName copy];
currentElement1=[attributeDict copy];
item = [[NSMutableDictionary alloc] init];
if ([elementName isEqualToString:#"item"]) {
// clear out our story item caches...
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentString=[[NSMutableString alloc] init];
currentImage = [[NSMutableString alloc] init];
currentContent=[[NSMutableString alloc]init];
}
if ([elementName isEqualToString:#"enclosure"])
{
currentString=[attributeDict objectForKey:#"url"];
// NSLog(#"what is my current string:%#",currentString);
[item setObject:currentString forKey:#"url"];
}
if ([elementName isEqualToString:#"itunes:image"])
{
currentImage = [attributeDict objectForKey:#"href"];
[item setObject:currentImage forKey:#"href"];
// NSLog(#"the item current string:%#",item);
NSString *imagefile1 = [item objectForKey:#"href"];
NSString *escapedURL=[imagefile1 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
UIImage *image1 = [[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:escapedURL]]];
NSLog(#"here we go dis is awesome:%#",image1);
//cell.imageView.image=image1;
image.image=image1;
}
}
- (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:#"description"];
[item setObject:currentContent forKey:#"content:encoded"];
[item setObject:currentDate forKey:#"pubDate"];
[stories addObject:[item copy]];
}
}
parse XML
Download Image to disk
load Image into ImageView
add imageView to headerView
Each of this step is well documented on SO, developer.apple.com and elsewhere.