Core Data text into URL for RSS iphone app
I have this code to configure a cell for Core Data: Code:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[managedObject valueForKey:@"data"] description];
}
But what i want to do is when i click the row, here: Code:
- (voi开发者_开发技巧d)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:@"RssFunViewController" bundle:nil];
//NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[self.navigationController pushViewController:rssFun animated:YES];
[rssFun release];
}
Insert the row text into the URL here: Code:
-(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://news.search.yahoo.com/rss?ei=UTF-8&p=lindsay+lohan&fr=news-us-ss"];
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;
}
So where it says lindsay+lohan, i will put the users search term in here. The thing is, the 3rd piece of code is in BlogRss.m and the first two bits and in RootViewController.m?? Not sure how to make the link?? Any ideas...
Thanks
You need to pass the NSManagedObject
into the incoming view controller:
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
// Navigation logic may go here -- for example, create and push another view controller.
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:@"RssFunViewController" bundle:nil];
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[rssFun setSelectedObject:selectedObject];
[[self navigationController] pushViewController:rssFun animated:YES];
[rssFun release], rssFun = nil;
}
This means that your RssFunViewController
needs to have a property called selectedObject
which is declared as a NSManagedObject
.
Then you can finish your method:
- (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];
NSString *terms = [[self selectedObject] vaueForKey:@"data"];
NSURL *url = [NSURL URLWithString:[NSString stirngWithFormat:@"http://news.search.yahoo.com/rss?ei=UTF-8&p=%@&fr=news-us-ss", terms]];
精彩评论