【问题标题】:iOS: memory increase when scrolling in tableView in the FXForms projectiOS:在 FXForms 项目中的 tableView 中滚动时内存增加
【发布时间】:2018-03-30 08:38:46
【问题描述】:

当我用FXForms 创建一个表单时,它非常流畅,记忆还可以。问题是你向下和向上滚动的次数越多,内存就越多,这使得滚动非常缓慢,非常糟糕。 我在a ticketanother ticket 中读到,FXForms 的表格视图不使用单元格回收。

我怎样才能找到解决这个问题的方法?

- (UITableViewCell *)cellForField:(FXFormField *)field
{
    //FIXME: memory leak recycle cells

    //don't recycle cells - it would make things complicated
    Class cellClass = field.cellClass ?: [self cellClassForField:field];
    NSString *nibName = NSStringFromClass(cellClass);
    if ([nibName rangeOfString:@"."].location != NSNotFound)
    {
        nibName = nibName.pathExtension; //Removes Swift namespace
    }
    if ([field.mandatory isKindOfClass:[NSString class]])
    {
        if ([field.mandatory isEqualToString:@"YES"])
        {
            NSString *string = [field.title stringByReplacingOccurrencesOfString:@" " withString:@""];
            BOOL isNotEmpty = ![string isEqualToString:@""];
            if (isNotEmpty)
            {
                if (![[string substringToIndex:1] isEqualToString:mandatoryCharacter])
                {
                    [field setValue: [NSString stringWithFormat:@"%@%@", mandatoryCharacter, field.title] forKey:@"title"];
                }
            }
        }
    }
    if ([[NSBundle mainBundle] pathForResource:nibName ofType:@"nib"])
    {
        //load cell from nib
        return [[[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil] firstObject];
    }
    else
    {
        //hackity-hack-hack
        UITableViewCellStyle style = UITableViewCellStyleDefault;
        if ([field valueForKey:@"style"])
        {
            style = [[field valueForKey:@"style"] integerValue];
        }
        else if (FXFormCanGetValueForKey(field.form, field.key))
        {
            style = UITableViewCellStyleValue1;
        }

        //don't recycle cells - it would make things complicated
        return [[cellClass alloc] initWithStyle:style reuseIdentifier:NSStringFromClass(cellClass)];
    }
}

提前致谢。

【问题讨论】:

    标签: ios objective-c uitableview fxforms


    【解决方案1】:

    将你的代码放入 autoreleasepool 并检查

    例如:

    -(UITableViewCell *)cellForField:(FXFormField *)field {@autoreleasepool {}}
    

    【讨论】:

    • @sachin khaire 你好,我试过了,但它并没有改变内存增加...
    • 请避免重用标识符:是重用您的 cellClass 及其内容。您需要找到reuseIdentifier.thanks的替代品
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 2013-10-07
    • 1970-01-01
    相关资源
    最近更新 更多