我正在使用以下代码在表格视图中显示图像,
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[xmlParser templates] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Temp *currentTemplate = [[xmlParser templates] objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
CGRect contentNameLabelFrame = CGRectMake(64, 2, 250, 20);
UILabel *contentNameLabelF = [[UILabel alloc] initWithFrame:contentNameLabelFrame];
contentNameLabelF.tag = 0011;
contentNameLabelF.font = [UIFont boldSystemFontOfSize:12];
contentNameLabelF.text = @"Template Name:";
contentNameLabelF.textColor = [UIColor orangeColor];
[cell.contentView addSubview:contentNameLabelF];
CGRect contentFrame = CGRectMake(115, 2, 250, 20);
UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
contentLabel.tag = 0012;
contentLabel.font = [UIFont boldSystemFontOfSize:12];
[cell.contentView addSubview:contentLabel];
CGRect contentnumberofcontacts = CGRectMake(63, 20, 250, 13);
UILabel *contentnumberofcontactsLabel = [[UILabel alloc] initWithFrame:contentnumberofcontacts];
contentnumberofcontactsLabel.tag = 0013;
contentnumberofcontactsLabel.font = [UIFont boldSystemFontOfSize:10];
contentnumberofcontactsLabel.text = @"Image:";
contentnumberofcontactsLabel.textColor = [UIColor brownColor];
[cell.contentView addSubview:contentnumberofcontactsLabel];
CGRect contentnumberFrame = CGRectMake(115, 20, 250, 13);
UILabel *contentnumberLabel = [[UILabel alloc] initWithFrame:contentnumberFrame];
contentnumberLabel.tag = 0014;
contentnumberLabel.font = [UIFont systemFontOfSize:10];
[cell.contentView addSubview:contentnumberLabel];
CGRect contentstatus = CGRectMake(78, 35, 250, 10);
UILabel *contentstatuslabel = [[UILabel alloc] initWithFrame:contentstatus];
contentstatuslabel.tag = 0015;
contentstatuslabel.font = [UIFont boldSystemFontOfSize:10];
contentstatuslabel.text = @"Category:";
contentstatuslabel.textColor = [UIColor grayColor];
[cell.contentView addSubview:contentstatuslabel];
CGRect statusFrame = CGRectMake(115, 35, 250, 10);
UILabel *statusLabel = [[UILabel alloc] initWithFrame:statusFrame];
statusLabel.tag = 0016;
statusLabel.font = [UIFont systemFontOfSize:10];
[cell.contentView addSubview:statusLabel];
}
UILabel *contentLabel = (UILabel *)[cell.contentView viewWithTag:0012];
contentLabel.text = [currentTemplate templateName];
UILabel *contentnumberLabel = (UILabel *)[cell.contentView viewWithTag:0014];
contentnumberLabel.text = [currentTemplate imagePath];
UILabel *statusLabel = (UILabel *)[cell.contentView viewWithTag:0016];
statusLabel.text = [currentTemplate category];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
xmlParser = [[ViewController alloc] loadXMLByURL:@"http://www.xxxxx.net/xxxxx/xxxx.aspx?type=xxxxx&xxxx="];
}
-(id)loadXMLByURL:(NSString *)urlString
{
_templates = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"template_maste"])
{
currentTemplate = [Temp alloc];
}
if ([elementName isEqualToString:@"img_path"])
{
currentTemplate = [Temp alloc];
isStatus = YES;
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"Template_name"])
{
currentTemplate.templateName = currentNodeContent;
}
if([elementName isEqualToString:@"img_path"])
{
currentTemplate.imagePath = currentNodeContent;
}
if([elementName isEqualToString:@"Category"])
{
currentTemplate.category = currentNodeContent;
}
if([elementName isEqualToString:@"template_maste"])
{
[self.templates addObject:currentTemplate];
currentTemplate = nil;
currentNodeContent = nil;
}
}
我能够在 tableView 中显示图像的路径,但我需要从 url 显示 tableView 中的图像。
我搜索了解决方案,但我无法获得解决方案,
提前致谢。