簡體   English   中英

我如何在表格視圖的頂部顯示新圖像

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

我通過傳遞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];

然后圖像顯示良好。

但是現在我在這里有一個問題。

我從Web服務器上獲得了一些新圖像,我需要將它們顯示在表格視圖的頂部。

按照我的實現,我需要更改所有圖像名稱。

那不是正確的方法,有沒有其他替代方法或比我更好的方法。

誰能幫幫我嗎。

預先謝謝你

看到這個答案:

如何在表格視圖頂部的數組中添加新元素

這比我對同一問題的回答要好得多,但是兩者都可以。

我剛剛確認這確實將對象向下移動了一個,所以這應該起作用。

編輯:對不起,我讀錯了你的問題。 至於更改圖像名稱,我認為唯一可行的方法是遍歷數組並在添加新對象后更改名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM