我使用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