图像视图使app变慢

时间:2015-04-07 07:45:45

标签: ios uiimageview base64

在我的iOS应用程序中,我在Tableviewcell中有一个图像视图。在添加该imageview之前,该应用程序表现平稳。现在它在所有设备上都很慢。

图像作为base 64编码字符串保存在数据库中,并将其解码为图像并加载到imageview。解码在后台线程中完成。

    if(info.image !=nil) {


           UIImage *image = [_imageCache objectForKey:info.threadID];

        if (image)
        {
            // if we have an cachedImage sitting in memory already, then use it

            cell.alignImageView.image = image;
        }
        else
        {
            UIActivityIndicatorView *spinner=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            spinner.center=cell.alignImageView.center;
            spinner.hidesWhenStopped=YES;
            [cell.alignImageView addSubview:spinner];
            [spinner startAnimating];


            // the get the image in the background

            [self.queue addOperationWithBlock:^{

                // get the UIImage


                NSArray* foo = [info.image componentsSeparatedByString: @","];
                NSString* day = [foo objectAtIndex: 1];

                NSData *data = [NSData dataFromBase64String:day];


                UIImage *image = [UIImage imageWithData:data];



                // if we found it, then update UI

                if (image)
                {
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        // if the cell is visible, then set the image

                        if (cell)
                            [spinner stopAnimating];

                            cell.alignImageView.image = image;
                    }];
                    [_imageCache setObject:image forKey:info.threadID];
                }
            }];
        }




    }

0 个答案:

没有答案