Я делаю простую программу чтения RSS, и она должна открывать ссылку в Safari, но ничего не происходит, когда я нажимаю на ячейку.Вот что у меня есть:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Navigation Logic:
int storyIndex = [indexPath indexAtPosition: [indexPath length] -1];
NSString *storyLink = [[stories objectAtIndex: storyIndex] objectForKey:@"link"];
//cleaning up the link...
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"/n" withString:@""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"link: %@", storyLink);
//open in Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
Вот журнал консоли:
2011-06-27 20:03:51.817 ParadiseBeats[26927:207] all done
2011-06-27 20:03:51.818 ParadiseBeats[26927:207] stories array had 20 items
2011-06-27 20:03:53.758 ParadiseBeats[26927:207] link: technobuffalo.com/companies/apple/…
И куда я положил ссылку:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([stories count] == 0) {
NSString *path = @"http://www.technobuffalo.com/feed/";
[self parseXMLFileAtURL:path];
}
}
Вот код анализа:
-(void)parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *__strong)qName attributes:(NSDictionary *__strong)attributeDict {
currentElement = [elementName copy];
if([elementName isEqualToString:@"item"]){
//clear out story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *__strong)elementName namespaceURI:(NSString *__strong)namespaceURI qualifiedName:(NSString *__strong)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"summary"];
[item setObject:currentDate forKey:@"date"];
[stories addObject:[item copy]];
NSLog(@"adding story: %@", currentTitle);
}
}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *__strong)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:@"pubDate"]) {
[currentDate appendString:string];
}
else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
}
}