UITableViewCell与UITextView阻止UI

时间:2015-12-12 18:20:49

标签: ios uitableview uitextview tableviewcell

我在单元格内部有一个UITextView,当滚动UI时会冻结一段短暂但明显的时间,等待创建单元格。

与textviews相关的任何类似经历?为什么需要时间来创建这样的单元格?它可以在后台线程上创建以避免冻结吗?

- (id)initWithStyle:(UITableViewCellStyle)style
    reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:reuseIdentifier];
    if (!self) {
        return nil;
    }

    [self setupTextView];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];

    return self;
}

- (void)setupTextView
{
    UITextView *textView = [[UITextView alloc] init];
    textView.translatesAutoresizingMaskIntoConstraints = NO;

    textView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textView.layer.borderWidth = 0.4f;
    textView.layer.cornerRadius = 4.0f;

    textView.textColor = [UIColor lightGrayColor];

    [self.contentView addSubview:textView];
    [self.contentView addConstraint:[NSLayoutConstraint
                                     constraintWithItem:textView
                                     attribute:NSLayoutAttributeHeight
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.contentView
                                     attribute:NSLayoutAttributeHeight
                                     multiplier:1.0
                                     constant:-18.0]];
    [self.contentView addConstraint:[NSLayoutConstraint
                                     constraintWithItem:textView
                                     attribute:NSLayoutAttributeWidth
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.contentView
                                     attribute:NSLayoutAttributeWidth
                                     multiplier:1.0
                                     constant:-18.0]];
    [self.contentView addConstraint:[NSLayoutConstraint
                                     constraintWithItem:textView
                                     attribute:NSLayoutAttributeCenterY
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.contentView
                                     attribute:NSLayoutAttributeCenterY
                                     multiplier:1.0
                                     constant:0.0]];
    [self.contentView addConstraint:[NSLayoutConstraint
                                     constraintWithItem:textView
                                     attribute:NSLayoutAttributeCenterX
                                     relatedBy:NSLayoutRelationEqual
                                     toItem:self.contentView
                                     attribute:NSLayoutAttributeCenterX
                                     multiplier:1.0
                                     constant:0.0]];

    _textView = textView;
}

0 个答案:

没有答案