Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bradnet

macrumors newbie
Original poster
Mar 8, 2010
20
0
hi guys

can someone please help me i've been trying to use this tutorial to create an rssreader that i search through but i can't seem to get it to work.

http://imthi.com/blog/programming/iphone-rss-reader-application-with-source-code.php

Here is the code for the rss reader and i'm using the following code for the search facility

http://clingingtoideas.blogspot.com/2010/02/uitableview-how-to-part-2-search.html

i think the problem is that i am trying to search the contents of a class where as these examples use a NSMutableArray to search. If anyone could help me populate an NSMutableArray with the contents of the blogrssparser then i may be able to complete the rest myself.

Thankyou in advance

Thanks
Brad
 

seepel

macrumors 6502
Dec 22, 2009
471
1
The best way to get help on these forums is to post your specific problem and your specific failure. What code are you running? What do you expect it to do? What does it do?
 

bradnet

macrumors newbie
Original poster
Mar 8, 2010
20
0
all i want to do is create a nsmutablearray from the objects from the bloggrss class so that i can then use this array for the search bar here is the code for the class and also the viewdidload and cellforrow code hopefully this will help.

Code:
#import "BlogRss.h"


@implementation BlogRss

@synthesize title = _title;
@synthesize description = _description;
@synthesize linkUrl = _linkUrl;
@synthesize mineralogy = _mineralogy;
@synthesize rarity = _rarity;
@synthesize mediaUrl = _mediaUrl;

-(void)dealloc{
	self.title = nil;
	self.description = nil;
	self.linkUrl = nil;
	self.mineralogy = nil;
	self.rarity = nil;
	self.mediaUrl = nil;
	[super dealloc];
}

@end


- (void)viewDidLoad {
	[super viewDidLoad];
	[self toolbarInit];
	_rssParser = [[BlogRssParser alloc]init];
	self.rssParser.delegate = self;
	[[self rssParser]startProcess];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
	if(nil == cell){
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
	}
	cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
	cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	return cell;
}

If anyone can help create this array so that i can call the search would be much appreciated.

Thanks
Brad
 
Last edited by a moderator:

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
The code u posted isn't giving us much to go on with, and u aren't using [ code] brackets, so i see smiley faces.. Which don't make me happy.

U are assigning variables which we can't see what they are.. So with just this, can't help you.
 

bradnet

macrumors newbie
Original poster
Mar 8, 2010
20
0
ok here is all the code i think you may need the parser.m

Code:
#import "BlogRssParser.h"
#import "BlogRss.h"

@implementation BlogRssParser

@synthesize currentItem = _currentItem;
@synthesize currentItemValue = _currentItemValue;
@synthesize rssItems = _rssItems;
@synthesize delegate = _delegate;
@synthesize retrieverQueue = _retrieverQueue;


- (id)init{
	if(![super init]){
		return nil;
	}
	_rssItems = [[NSMutableArray alloc]init];
	return self;
}

- (NSOperationQueue *)retrieverQueue {
	if(nil == _retrieverQueue) {
		_retrieverQueue = [[NSOperationQueue alloc] init];
		_retrieverQueue.maxConcurrentOperationCount = 1;
	}
	return _retrieverQueue;
}

- (void)startProcess{
	SEL method = @selector(fetchAndParseRss);
	[[self rssItems] removeAllObjects];
	NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self 
																	 selector:method 
																	   object:nil];
	[self.retrieverQueue addOperation:op];
	[op release];
}

-(BOOL)fetchAndParseRss{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

	//To suppress the leak in NSXMLParser
	[[NSURLCache sharedURLCache] setMemoryCapacity:0];
	[[NSURLCache sharedURLCache] setDiskCapacity:0];
	
	NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.com/Data.xml"];
	BOOL success = NO;
	NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	[parser setDelegate:self];
	[parser setShouldProcessNamespaces:YES];
	[parser setShouldReportNamespacePrefixes:YES];
	[parser setShouldResolveExternalEntities:NO];
	success = [parser parse];
	[parser release];
	[pool drain];
	return success;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
 qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{
	if(nil != qualifiedName){
		elementName = qualifiedName;
	}
	if ([elementName isEqualToString:@"item"]) {
		self.currentItem = [[[BlogRss alloc]init]autorelease];
	} else if([elementName isEqualToString:@"title"] || 
			  [elementName isEqualToString:@"description"] ||
			  [elementName isEqualToString:@"mediaUrl"] ||
			  [elementName isEqualToString:@"link"] ||
			  [elementName isEqualToString:@"mineralogy"] ||
			  [elementName isEqualToString:@"rarity"]) {
		self.currentItemValue = [NSMutableString string];
	} else {
		self.currentItemValue = nil;
	}	
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	if(nil != qName){
		elementName = qName;
	}
	if([elementName isEqualToString:@"title"]){
		self.currentItem.title = self.currentItemValue;
	}else if([elementName isEqualToString:@"description"]){
		self.currentItem.description = self.currentItemValue;
	}else if([elementName isEqualToString:@"link"]){
		self.currentItem.linkUrl = self.currentItemValue;
	}else if([elementName isEqualToString:@"mediaUrl"]){
		self.currentItem.mediaUrl = self.currentItemValue;
	}else if([elementName isEqualToString:@"mineralogy"]){
		self.currentItem.mineralogy = self.currentItemValue;
	}else if([elementName isEqualToString:@"rarity"]){
		self.currentItem.rarity = self.currentItemValue;
	}else if([elementName isEqualToString:@"item"]){
		[[self rssItems] addObject:self.currentItem];
	}
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
	if(nil != self.currentItemValue){
		[self.currentItemValue appendString:string];
	}
}

- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock{
	//Not needed for now
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
	if(parseError.code != NSXMLParserDelegateAbortedParseError) {
		[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
		[(id)[self delegate] performSelectorOnMainThread:@selector(processHasErrors)
		 withObject:nil
		 waitUntilDone:NO];
	}
}



- (void)parserDidEndDocument:(NSXMLParser *)parser {
	[(id)[self delegate] performSelectorOnMainThread:@selector(processCompleted)
	 withObject:nil
	 waitUntilDone:NO];
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}


-(void)dealloc{
	self.currentItem = nil;
	self.currentItemValue = nil;
	self.delegate = nil;
	
	[_rssItems release];
	[super dealloc];
}

@end

and here is the object class that i would like to convert to a NSMutableArray

Code:
#import "BlogRss.h"


@implementation BlogRss

@synthesize title = _title;
@synthesize description = _description;
@synthesize linkUrl = _linkUrl;
@synthesize mineralogy = _mineralogy;
@synthesize rarity = _rarity;
@synthesize mediaUrl = _mediaUrl;

-(void)dealloc{
	self.title = nil;
	self.description = nil;
	self.linkUrl = nil;
	self.mineralogy = nil;
	self.rarity = nil;
	self.mediaUrl = nil;
	[super dealloc];
}

@end

now what i would like to do is to search the objects for the relevant information using a UISearchBar and then populate a search results from this information and display this on the screen, but i've not had any luck in doing it this way so i was hoping that i may be able to get some help on how to populate the NSMutableArray from the contents of this class that is parsed from the xml and then search this array which may be an easier option as all the tutorials i can find only deal with searching an array.

if you need any more information then please ask and i'll do my best to post it.

Thanks
Brad

the link in the first posting will give you the code i was trying to use for the searchbar.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.