如何在表格视图标题上添加图像....从rss feed中读取图像并将其存储在名为item的数组中,代码为
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 69.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* headerView = [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 69.0)];
headerView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"1" ofType: @"jpg"]]];
return headerView;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
currentElement1=[attributeDict copy];
item = [[NSMutableDictionary alloc] init];
if ([elementName isEqualToString:@"item"]) {
// clear out our story item caches...
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentString=[[NSMutableString alloc] init];
currentImage = [[NSMutableString alloc] init];
currentContent=[[NSMutableString alloc]init];
}
if ([elementName isEqualToString:@"enclosure"])
{
currentString=[attributeDict objectForKey:@"url"];
// NSLog(@"what is my current string:%@",currentString);
[item setObject:currentString forKey:@"url"];
}
if ([elementName isEqualToString:@"itunes:image"])
{
currentImage = [attributeDict objectForKey:@"href"];
[item setObject:currentImage forKey:@"href"];
// NSLog(@"the item current string:%@",item);
NSString *imagefile1 = [item objectForKey:@"href"];
NSString *escapedURL=[imagefile1 stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
UIImage *image1 = [[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:escapedURL]]];
NSLog(@"here we go dis is awesome:%@",image1);
//cell.imageView.image=image1;
image.image=image1;
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:currentContent forKey:@"content:encoded"];
[item setObject:currentDate forKey:@"pubDate"];
[stories addObject:[item copy]];
}
}
答案 0 :(得分:0)
这一步的每一步都在SO,developer.apple.com和其他地方都有详细记录。