简体   繁体   English

我如何在表格视图的顶部显示新图像

[英]how can i display new images at the top of the table view

i am getting images from the .net web server by passing xml parameters. 我通过传递xml参数从.net Web服务器获取图像。

i am getting more that 20 images and i am saving images in iphone simulator documents one by one like this. 我得到了20多个图像,并且像这样一个一个地将图像保存在iPhone模拟器文档中。

-(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..... 那么图像将像这样保存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. 我从Web服务器上获得了一些新图像,我需要将它们显示在表格视图的顶部。

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. 至于更改图像名称,我认为唯一可行的方法是遍历数组并在添加新对象后更改名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM