Objective-C、iPhone RSS 阅读器应用程序查询 - 如何将 RSS 提要显示组织成组?

发布于 2024-09-16 04:05:27 字数 426 浏览 9 评论 0原文

我的编程非常不幸。我对 Objective-C 还很陌生,但我正在努力尽快学习。

我需要完成一个适用于 iPhone 的 RSS 阅读器应用程序,这是一个相对简单的应用程序,它解析 rss 提要,将其显示在导航表视图中,当您单击一篇文章时,您将被带到主页。

不幸的是,我在解析方面遇到困难。目前,该程序下载所有文章,但我想将其显示在 10 篇文章的列表中,并在底部添加一个“下一步”按钮。单击下一个按钮后,解析将继续,并显示接下来的 10 个。

很抱歉,我无法向您展示我目前正在使用的代码,因为我在家用计算机上,而该项目在办公室 Mac 上。如果有人能给我一些想法,我将不胜感激。我尝试了多种方法(例如,制作一个额外的数组作为文章计数器,以便我可以记录哪篇文章属于哪个列表),但我不断遇到障碍,因为我只是不知道如何很好地使用该程序足以做到这一点。

拜托,我很需要帮助!谢谢。

I've been very unfortunate with my programming. I am still rather new to Objective-C, but I am trying to learn as quickly as possible.

I need to complete an RSS Reader for iPhones application, a relatively simple one which parses the rss feed, displays it in a navigation-table view and when you click on an article you are taken to a main page.

Unfortunately, I am having difficulty with the parsing aspect. Currently, the program downloads all the articles, but I would like to display it in lists of 10, along with a next button at the bottom. Once the next button is clicked, the parsing continues and the next 10 are on display.

I am sorry but I cannot show you the code I am using at the moment as I am on my home computer and the project is on the office mac. If anyone could give me some Ideas i would be most grateful. I have tried a number of methods (making an additional array to act as an article counter so I could record which article is which for which list, for example) but i keep running into roadblocks as I just dont know how to use the program well enough to do that.

Please, I am in a lot of need! Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2024-09-23 04:05:27

(这又是我)
如果这相当模糊,我很抱歉,但我相信我可以提供示例代码。我试图让程序在解析 10 篇文章后暂停解析,显示这 10 篇文章,然后继续解析并在按下下一个按钮时显示另外 10 篇文章。

在 parser.m 中,我写了:

- (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];
    self.currentTitle = [[NSMutableString alloc] init];
    self.currentDate = [[NSMutableString alloc] init];
    self.currentSummary = [[NSMutableString alloc] init];
    self.currentLink = [[NSMutableString alloc] init];
    self.currentImage = [[NSMutableString alloc] init];
}//IF END
//podcast url is an attribute of the element enclosure
if ([currentElement isEqualToString:@"enclosure"]) {
    [currentImage appendString:[attributeDict objectForKey:@"url"]];
    NSLog(@"Image = %@", currentImage);
}//IF END
else if([currentElement isEqualToString:@"img"]){
    [currentImage appendString:[attributeDict objectForKey:@"src"]];
    NSLog(@"Image = %@", currentImage);
}//ELSE IF END

}

我还有 didEndElement 和 Found 字符部分:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName{

if ([elementName isEqualToString:@"item"]) {
    [item setObject:self.currentTitle forKey:@"title"];
    [item setObject:self.currentLink forKey:@"link"];
    [item setObject:self.currentSummary forKey:@"summary"];
    [item setObject:self.currentImage forKey:@"image"];


// Parse date here
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setDateFormat:@"EEE, d MMM yyyy"]; // Thu, 18 Jun 2010 04:48:09 -0700
    NSLog(@"FC date1 = %@", self.currentDate);
    NSDate *date = [[NSDate alloc] init]; 
    date = [dateFormatter dateFromString:currentDate];
    NSLog(@"FC date2 = %@", date);

    [item setObject:self.currentDate forKey:@"date"];
    //[item setObject:date forKey:@"date"];
    [date release];
    [items addObject:[item copy]];
    NSLog(@"Item details = %@", items);

    [count addObject:[item objectForKey:@"title"]];
    NSLog(@"count = %@", count);
}//IF END

}

我在格式化日期方面也遇到了一些问题,但这是一个小问题。

另外:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if ([currentElement isEqualToString:@"title"]) {
    [self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
    [self.currentLink appendString:string];
} else if ([currentElement isEqualToString:@"image"]) {
    [self.currentImage appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
    [self.currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
    [self.currentDate appendString:string];
    NSCharacterSet* charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@" \n"];
    [self.currentDate setString: [self.currentDate stringByTrimmingCharactersInSet: charsToTrim]];
}//IF-ELSE-IF END

}

如果有人能给我一些关于如何暂停程序的提示...或者允许我以 10 组为一组进行解析...我不知所措;_;

感谢您抽出时间。

(This is me again)
I am sorry if this is rather vague, but I believe I can give sample code. I am trying to make it that the program pauses parsing after 10 articles are parsed, displays those 10, then continues parsing and displaying another 10 if a next button is pressed.

In the parser.m, i have written:

- (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];
    self.currentTitle = [[NSMutableString alloc] init];
    self.currentDate = [[NSMutableString alloc] init];
    self.currentSummary = [[NSMutableString alloc] init];
    self.currentLink = [[NSMutableString alloc] init];
    self.currentImage = [[NSMutableString alloc] init];
}//IF END
//podcast url is an attribute of the element enclosure
if ([currentElement isEqualToString:@"enclosure"]) {
    [currentImage appendString:[attributeDict objectForKey:@"url"]];
    NSLog(@"Image = %@", currentImage);
}//IF END
else if([currentElement isEqualToString:@"img"]){
    [currentImage appendString:[attributeDict objectForKey:@"src"]];
    NSLog(@"Image = %@", currentImage);
}//ELSE IF END

}

I also have the didEndElement and Found characters section:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName{

if ([elementName isEqualToString:@"item"]) {
    [item setObject:self.currentTitle forKey:@"title"];
    [item setObject:self.currentLink forKey:@"link"];
    [item setObject:self.currentSummary forKey:@"summary"];
    [item setObject:self.currentImage forKey:@"image"];


// Parse date here
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dateFormatter setDateFormat:@"EEE, d MMM yyyy"]; // Thu, 18 Jun 2010 04:48:09 -0700
    NSLog(@"FC date1 = %@", self.currentDate);
    NSDate *date = [[NSDate alloc] init]; 
    date = [dateFormatter dateFromString:currentDate];
    NSLog(@"FC date2 = %@", date);

    [item setObject:self.currentDate forKey:@"date"];
    //[item setObject:date forKey:@"date"];
    [date release];
    [items addObject:[item copy]];
    NSLog(@"Item details = %@", items);

    [count addObject:[item objectForKey:@"title"]];
    NSLog(@"count = %@", count);
}//IF END

}

I have also been having some issues with formatting the date, but thats a minor issue.

also:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if ([currentElement isEqualToString:@"title"]) {
    [self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
    [self.currentLink appendString:string];
} else if ([currentElement isEqualToString:@"image"]) {
    [self.currentImage appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
    [self.currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
    [self.currentDate appendString:string];
    NSCharacterSet* charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@" \n"];
    [self.currentDate setString: [self.currentDate stringByTrimmingCharactersInSet: charsToTrim]];
}//IF-ELSE-IF END

}

I would be most grateful if someone could give me a tip on what to do to pause the program...or allow me to parse in groups of 10...I am at a loss ;_;

Thank you for your time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文