i am getting images from the .net web server by passing xml parameters.
i am getting more that 20 images and i am saving images in iphone simulator documents one by one like this.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"photo"])
{
recordResults_photo = FALSE;
NSData *decode = [Base64 decode:resultData_photo];
NSString *theXML = [[NSString alloc] initWithData:decode encoding:NSUTF8StringEncoding];
NSData *decodedimage = [Base64 decode:theXML];
UIImage *image = [UIImage imageWithData:decodedimage];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(@"saving msg image %d",i);
NSString *pngFilePath = [NSString stringWithFormat:@"%@/image%d.png",docDir,i];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:YES];
}
}
then images are saving like this image0.png,image1.png,image2.png.....
and i am displaying these images in table view like this.
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/image%d.png",docDir,indexPath.row];
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(250, 05, 30, 30)];
img.image = [UIImage imageWithContentsOfFile:pngFilePath];
[cell.contentView addSubview:img];
then images are displayed well.
But now i have a problem here.
I am getting some more new images from the web server and i need to display them at the top of the table view.
As per my implementation i need to change all the image names.
That's not the proper way,is there any alternate way or better way than me.
can any one please help me.
Thank u in advance
See this answer:
how to add new elements in array at the top of the table view
It's much better than my answer to the same question but both would work.
I just confirmed that this does shift the objects down by one, so this should work.
EDIT: I'm sorry, I misread your question. As for changing the image names, the only way I see thats possible is by iterating through the array and changing the names once new objects are added.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.