1
我想创建一个简单的RSS阅读器显示“说明”,我想从RSS源获取“description
”标签,并在我的应用程序显示出来,任何帮助吗?从RSS源中的iOS应用
是不是最好使用NSXMLParser
或任何其他解析器,使我的工作容易吗?
我使用的源代码是:iOS programming RSS reader tutorial
我想创建一个简单的RSS阅读器显示“说明”,我想从RSS源获取“description
”标签,并在我的应用程序显示出来,任何帮助吗?从RSS源中的iOS应用
是不是最好使用NSXMLParser
或任何其他解析器,使我的工作容易吗?
我使用的源代码是:iOS programming RSS reader tutorial
与教程人离开什么。一切工作正常呐。他们 只是留下来使用说明项目。对 ...?
这里从教程云:
@interface ViewController(){
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
NSMutableString *desc; // Description .
}
只需粘贴此代码。作品般的魅力:
#pragma mark - parsing of RssFeed Values
-(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];
desc = [[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"];
[item setObject:desc forKey:@"description"];
[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];
}else if ([element isEqualToString:@"description"]){
[desc appendString:string];
}
}
-(void) parserDidEndDocument:(NSXMLParser *)parser{
[self.tableView reloadData];
}
使用此参数说明随时随地获得 的RSSFeed项目的说明。
这里是它完成:
-(void) tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *string = [feeds[indexPath.row] objectForKey: @"description"];
stringUrl = [feeds[indexPath.row] objectForKey:@"link"];
NSLog(@"Description %@", string);
actionSheet = [[UIActionSheet alloc] initWithTitle:string delegate:self cancelButtonTitle:Nil destructiveButtonTitle:@"OK" otherButtonTitles:@"GoTo URL", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
self.actionSheet.delegate = self;
switch (buttonIndex) {
case 0:
NSLog(@"ButtonIndex at 0");
break;
case 1:
NSLog(@"ButtonIndex at 1");
//Add your Segue functionalities over here to open link on the browser .
}
break;
}
}
如果你有这里的任何问题,PLZ使用 “%@” 来回串显示所有让我知道:::
Feed的内容,包括链接和说明。我只需要显示描述,是否有其他可能的方式? – Siva
您需要所有的描述或者只针对特定的行(Item)。 –
只有描述。当前的o/p类似于:“Feed”的URL,后面跟着描述。 – Siva