gpt4 book ai didi

iphone - Xcode 从 rss feed 获取图像 url

转载 作者:行者123 更新时间:2023-12-03 21:01:46 26 4
gpt4 key购买 nike

Xcode 新手,很高兴能得到这个问题的答案。我正在尝试从 RSS feed 获取图像 url 标签并将其添加到我的自定义表格 View 单元格中。其他文本我很好。

这是 rss 行:

<Item>
<title>this is a title</title>
<description>this is a description</description>
<link>http://www.something.com</link>
<pubDate>Fri, 09 Aug 2013</pubDate>
<enclosure type="image/jpg" url="http://www.ThisIsTheUrlIWant.com" />
</item>

这是我的代码的一部分,没有任何图像逻辑:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath {
CustomCellNews *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.titleLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
cell.descriptionLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"description"];
//set cell image here
return cell;
}

- (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];
description = [[NSMutableString alloc] init];
//image stuff
}
}

- (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:description forKey:@"description"];
//image stuff

[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"]) {
[ingress appendString:string];
}
//image stuff

}

谢谢

最佳答案

试试这个:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"enclosure"]) {
NSString *units = [attributeDict objectForKey:@"url"];
}
}

希望这有帮助。

关于iphone - Xcode 从 rss feed 获取图像 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206991/

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