我使用RSS阅读器,并且在我点击UITableViewCell
加载<link>
或UIWebView
或在该链接上打开Safari时正常工作。如何在可可触摸中处理HTML字符串
但是我真的想学习如何加载主题内容到而不是显示整个网站或跳转到Safari浏览器
在每各<item>
的RSS提要的应用程序有一个<body>
标签(并包含一个<Description>
alt text http://www.balexandre.com/temp/2010-04-13_0953.png
因此,而不是捕捉<link>
我指定的<body>
:包含主题内容,如下面所示的图像相同,但编码)。问题是,它不能正确:-(
在这个例子中工作,我只得到了内容,直到第一<br>
仅此而已。
- 我使用的是
NSString
,我会在C#中使用时,应我使用的任何其他对象,有没有更好的对象对这样的数据使用? - 我应该使用
UITextView
加载该信息(因为它有滚动的话)或者我应该使用UIWebView
呢?
钍谢谢你。
添加
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentBody = [NSMutableString new]; // added by me
currentCreator = [NSMutableString new]; // added by me
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[item setObject:currentBody forKey:@"body"]; // <----
[item setObject:currentCreator forKey:@"dc:creator"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"summary"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
} else if ([currentElement isEqualToString:@"body"]) {
[currentBody appendString:string]; // <----
} else if ([currentElement isEqualToString:@"dc:creator"]) {
[currentCreator appendString:string];
}
}
,并传递给我的web浏览器查看我:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyContent = [[stories objectAtIndex: storyIndex] objectForKey: @"body"];
// load web view
[self showWebPage:storyContent]; // <-- Here (storyContent variable) I only have the content until the first <br> :-(
}
我正在使用NSXMLParser获取RSS,这只是为'
'标记 – balexandre 2010-04-13 08:42:19Are您使用的NSMutableString构建''
标签内的字符串?如果没记错,应该继续下去,直到关闭标记(除非遇到里面,你正在分析在别的地方标记)。 – mgriepentrog 2010-04-13 08:54:39加入我的代码...我使用的NSMutableString: - / – balexandre 2010-04-13 09:06:36