gpt4 book ai didi

ios - 在 iOS 应用程序中显示来自 RSS 提要的 "description"

转载 作者:行者123 更新时间:2023-11-29 13:09:12 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的 RSS 阅读器,我想从 rss 提要中获取“description”标签并将其显示在我的应用程序中,有什么帮助吗?

是否建议使用 NSXMLParser 或任何其他解析器来简化我的工作?

我使用的源代码来自:iOS programming RSS reader tutorial

最佳答案

What else left with that tutorial . Everything works fine na. They just left to use the Description item . right ...?

这是该教程的内容:

@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];
}

Use this parameter Desc anywhere to get the Description of the RSSFeed item.

这是它的完成:

-(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;
}

}

If you have any problem here , Plz let me know :::

关于ios - 在 iOS 应用程序中显示来自 RSS 提要的 "description",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17801691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com