[英]Core Data text into URL for RSS iphone app
我有以下代碼可為核心數據配置單元格:代碼:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[managedObject valueForKey:@"data"] description];
}
但是我想做的是當我單擊以下行時:代碼:
- (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];
[self.navigationController pushViewController:rssFun animated:YES];
[rssFun release];
}
在此處將行文本插入URL:代碼:
-(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;
}
所以說lindsay + lohan的地方,我將把用戶搜索詞放在這里。 關鍵是,第三段代碼在BlogRss.m和前兩位以及RootViewController.m中? 不確定如何建立鏈接?? 有任何想法嗎...
謝謝
您需要將NSManagedObject
傳遞到傳入的視圖控制器中:
- (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;
}
這意味着您的RssFunViewController
需要具有一個名為selectedObject
的屬性,該屬性被聲明為NSManagedObject
。
然后,您可以完成您的方法:
- (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]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.