【问题标题】:how can i display new images at the top of the table view如何在表格视图的顶部显示新图像
【发布时间】:2011-04-22 18:04:41
【问题描述】:

我通过传递 xml 参数从 .net Web 服务器获取图像。

我得到了超过 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];

    }
}

然后图像像这样保存 image0.png,image1.png,image2.png.....

我正在像这样的表格视图中显示这些图像。

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];

然后图像显示良好。

但是现在我这里有个问题。

我正在从网络服务器获取更多新图像,我需要将它们显示在表格视图的顶部。

根据我的实现,我需要更改所有图像名称。

这不是正确的方法,有没有比我更好的替代方法。

谁能帮帮我。

提前谢谢你

【问题讨论】:

    标签: iphone


    【解决方案1】:

    看到这个答案:

    how to add new elements in array at the top of the table view

    这比我对同一个问题的回答要好得多,但两者都可以。

    我刚刚确认这确实将对象向下移动了一个,所以这应该可以工作。

    编辑:对不起,我误读了你的问题。至于更改图像名称,我认为可能的唯一方法是遍历数组并在添加新对象后更改名称。

    【讨论】:

    • 但是我怎样才能将图像排列成数组。
    • 您无法将 UIImage 添加到 NSMutableArray 中吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    相关资源
    最近更新 更多