0

当我使用FXForms创建表单时,它非常流畅,内存还可以。问题是你向下和向上滚动的次数越多,内存就越多,这使得滚动非常缓慢,非常糟糕。我在一张票另一张票中读到 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)];
    }
}

提前致谢。

4

1 回答 1

0

将您的代码放入 autoreleasepool 并检查

例如:

-(UITableViewCell *)cellForField:(FXFormField *)field {@autoreleasepool {}}
于 2018-03-31T10:48:09.253 回答