我从服务器加载了XML数据(包括图像,文本......),并通过tableview显示该数据。
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"user_id"])
{
Myxml.str_user_id = currentNodeContent;
}
else if([elementName isEqualToString:@"username"])
{
Myxml.str_username = currentNodeContent;
}
else if([elementName isEqualToString:@"avatar"])
{
Myxml.str_avatar=currentNodeContent;
Myxml.imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:currentNodeContent]];
}
else if([elementName isEqualToString:@"full_name"])
{
Myxml.str_full_name=currentNodeContent;
}
else if([elementName isEqualToString:@"cups"])
{
Myxml.str_cups=currentNodeContent;
}
//--------Record End-------
else if([elementName isEqualToString:@"record"])
{
[RecordArray addObject:Myxml];
[Myxml release];
Myxml = nil;
}
[currentNodeContent release];
currentNodeContent = nil;
currentNodeContent = [[NSMutableString alloc]init];
}
现在,在主视图控制器中,我收集名为" LabelArray"的NSMutableArray中的所有数据。在init方法
Connection=[[NetworkConnection alloc]initConnection];
if (Connection.isReachable)
{
XmlDetail=[[TopPickerXML alloc]init];
LabelArray=[[NSMutableArray alloc]initWithArray:XmlDetail.RecordArray];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"Network connection unavailable..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
在cellForRowAtIndexPath的Table视图中,我显示这样的图像
img_BuddyAvtar=[[UIImageView alloc]init];
img_BuddyAvtar.frame=CGRectMake(10, 5, 120, 105);
img_BuddyAvtar.image=[UIImage imageWithData:TopPicker_record.imageData];
img_BuddyAvtar.backgroundColor=[UIColor clearColor];
[View_TableCell addSubview:img_BuddyAvtar];
现在,我的问题是,当我加载此视图时,需要时间来加载,然后显示包括我的文本和图像在内的所有数据。我如何预加载图像以便加载表格视图所需的时间更短?
答案 0 :(得分:0)
您必须缓存图片。
cellForItemAtIndexPath
标题在[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"your image URL"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
SELECT b.Series,
CASE
WHEN Series = 'DMS' THEN ROUND(b.Quantity,0)
ELSE ROUND(b.Quantity,2)
END AS Quantity
FROM bill b