iOS的表preVIEW图像发布 [英] iOS table preview image release

查看:142
本文介绍了iOS的表preVIEW图像发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试我的iPhone的RSS。它采用0笔尖文件。我会尽力为最佳,我可以来形容它,将张贴code如果需要,但我敢打赌,它的一个共同的解决方案,一个共同的现象。的问题是在一个tableviewcontroller,并将该溶液可能需要cellForRowAtIndexPath方法中实施。如果我向下滚动,preVIEW图像留在各自的点,直到异步加载队列该小区正确的图像。所以,如果我有数组项1的图像,我向下滚动到阵列项目20,对数组项1的图像将仍然存在,直到我的队列赶上并加载该图像。我怎样才能释放从细胞中,我没有观看图像?感谢您的时间。

下面是我的CellForRow ...

   - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
静态的NSString * CellIdentifier = @细胞;
CustomCell *电池= [的tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(细胞==零){
    电池= [[CustomCell页头] initWithFrame:方法CGRectZero reuseIdentifier:CellIdentifier];
}
ArticleItem *对象= _objects [indexPath.row]
cell.pr​​imaryLabel.text = object.title;
cell.secondaryLabel.text = object.strippedDescription;
cell.pr​​imaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.pr​​imaryLabel.numberOfLines = 0;
    cell.pr​​imaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.secondaryLabel.numberOfLines = 0;//图像preVIEW装载异步发送队列...
dispatch_queue_t队列= dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0ul);
dispatch_async(队列,^ {    * UIImage的preVIEW =零;
    如果(object.iG =无)
    {
        preVIEW = [UIImage的imageNamed:@CellLogo.png];
    }
    其他
    {
        preVIEW = [UIImage的imageWithData:object.iG];
    }
    dispatch_sync(dispatch_get_main_queue(),^ {        [细胞myImageView] setImage:preVIEW]。
        [细胞setNeedsLayout]
    });
});
返回细胞;
}

如果你收集,我有一个ArticleItem类拉动图像URL,并把它们转化成数据,我有一个CustomCell类做什么其所谓。
    CustomCell.h
    @interface CustomCell:{的UITableViewCell
        * UIImageView的myImageView;
    }
    @属性(非原子,强)的UIImageView * myImageView;
    @结束
    ================================================== ===
    CustomCell.m

   - (ID)initWithFrame:方法(的CGRect)帧reuseIdentifier:(* NSString的)reuseIdentifier {
如果(自= [超级initWithFrame:方法框架reuseIdentifier:reuseIdentifier]){
    //初始化code
            myImageView = [[UIImageView的页头]初始化];
    [self.contentView addSubview:myImageView];
}
返回自我;
}
- (无效){viewDidUnload
myImageView =零;
primaryLabel =零;
secondaryLabel =零;
}


解决方案

实施的UITableViewCell的子类中,为ImageView的属性。只要它得到从能见度远,它将被释放。描述只是概述,你可以自己根据需要滚动查看用法。

I'm testing an RSS on my iPhone. It uses 0 nib files. I'll try to describe it as best as I can, and will post code if its required, but I bet its a common phenomena with a common solution. The issue is in a tableviewcontroller, and the solution probably needs to be implemented in the CellForRowAtIndexPath method. If I scroll down, preview images stay in their respective spots until the async queue loads the correct image for that cell. So if I have an image for array item 1, and I scroll down to array item 20, the image for array item 1 will still be there until my queue catches up and loads that image. How can I release the images from cells that I am not viewing? Thank you for your time.

Here is my CellForRow...

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
ArticleItem *object = _objects[indexPath.row];
cell.primaryLabel.text = object.title;
cell.secondaryLabel.text = object.strippedDescription;
cell.primaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.primaryLabel.numberOfLines = 0;
    cell.primaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.secondaryLabel.numberOfLines = 0;

//Async dispatch queue for image preview loading...
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{ 

    UIImage *preview = nil;
    if (object.iG = nil)
    {
        preview = [UIImage imageNamed:@"CellLogo.png"];
    }
    else
    {
        preview = [UIImage imageWithData:object.iG];
    } 
    dispatch_sync(dispatch_get_main_queue(), ^{

        [[cell myImageView] setImage:preview];
        [cell setNeedsLayout];
    });
});
return cell;   
}

If you gather, I have an ArticleItem class which pulls the image URLS and turns them into data , and I have a CustomCell class which does what its called. CustomCell.h @interface CustomCell : UITableViewCell { UIImageView *myImageView; } @property(nonatomic,strong)UIImageView *myImageView; @end ===================================================== CustomCell.m

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
    // Initialization code
            myImageView = [[UIImageView alloc]init];


    [self.contentView addSubview:myImageView];       
}
return self;
}
-(void)viewDidUnload {
myImageView = nil;
primaryLabel = nil;
secondaryLabel = nil;
}

解决方案

Implement a subclass of UITableViewcell, make a property for imageview. As soon as it gets away from visibility, it will be released. Describing just the overview as you may yourself need to see the usage upon scrolling.

这篇关于iOS的表preVIEW图像发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆