iphone - 设置对象的图层会导致内存问题吗?

标签 iphone ios objective-c quartz-core

我的 cellForRowAtIndexPath 中有以下代码:

cell.appImageLogo.layer.cornerRadius = 10.0;  
cell.appImageLogo.layer.masksToBounds = YES;
cell.appImageLogo.layer.borderColor = [UIColor clearColor].CGColor;
cell.appImageLogo.layer.borderWidth = 2.0;

我的问题是:它会导致内存问题吗?如果是,如何释放它消耗的内存?任何帮助将不胜感激。

最佳答案

如果你的cell没有被重用并且cell数量不多,或者你的cell被重用,则不会导致内存问题。

如果您的单元格被重复使用,并且如果cornerRadiusborderColor等属性相同,您可以在单元格为时的语句中编写代码无

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"YOURSTRING";
    YourCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){

        cell = [[YourCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

        cell.appImageLogo.layer.cornerRadius = 10.0;  
        cell.appImageLogo.layer.masksToBounds = YES;
        cell.appImageLogo.layer.borderColor = [UIColor clearColor].CGColor;
        cell.appImageLogo.layer.borderWidth = 2.0;

        }
        // other different settings for different cells
        return cell;

    }

关于iphone - 设置对象的图层会导致内存问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15129112/

相关文章:

iphone - 如何检测三角形区域的触摸

ios - xcassets 和自定义 URL 方案启动图像

ios - 在 UIKit 中显示像素分数以实现平滑的慢动作

iphone - 何时使用 Core Data 的 NSMainQueueConcurrencyType?

ios - 如何调整 iCarouselTypeLinear View 移动到顶部的框架

objective-c - Xcode,为什么会自动添加一些约束?

iphone - NSUserDefaults 设置

iphone - UITableViewCell backgroundView 在不应该被重用时被重用

objective-c - 何时使用 InterfaceBuilder 构建 View ?

objective-c - Force unwrapped 在预期的参数类型中意味着什么?