Я хочу, чтобы отобразить изображения из URLПоказать изображения с помощью RSS поток в Objective C
Я использую контроллер представления таблицы в моей Objective C project..I я способен отображать текст и ссылки отлично но не в состоянии отображать изображения из URL ленты
Я использую следующий код
**TableViewController.h**
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController <NSXMLParserDelegate>
@property (strong, nonatomic) IBOutlet UITableView *TableView;
@end
TableViewController.m
#import "TableViewController.h"
#import "ViewController.h"
@interface TableViewController(){
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
NSString *imageType;
NSString *imageUrl;
}
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
feeds=[[NSMutableArray alloc ] init];
NSURL *url = [NSURL URLWithString:@"https://www.nasa.gov/rss/dyn/breaking_news.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:@"title"];
// cell.imageView.image= [[feeds objectAtIndex:indexPath.row] objectForKey:@"title"];
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];
}
if ([element isEqualToString:@"enclosure"]) {
imageType = [attributeDict objectForKey:@"type"];
imageUrl = [attributeDict objectForKey:@"url"];
}
}
-(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:imageType forKey:@"imageType"];
[item setObject:imageUrl forKey:@"imageUrl"];
[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];
}
}
-(void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey:@"link"];
[[segue destinationViewController] setUrl:string];
}
}
@end
Пожалуйста, помогите мне, чтобы отобразить изображения я застрял с this.Thanks
, где у вас установлен образ изображения на изображение ячейки? у вас создано какое-либо изображение на ячейке tableview –
@SKT да !! Я хочу отображать изображение на таблице Cell – Gitz
проверить ответ и просто добавить в него простое изображение, а затем проверить –