0

我正在使用 StoryBoard 和使用 Autolayout ,我在运行时为自定义单元格设置了约束。我还在ViewDidLayoutSubviews中设置了约束以处理设备方向。所以这需要时间来配置单元格并且我的单元格不能平滑滚动。有人可以帮我解决这个问题吗?如果我必须在运行时不设置约束,那么我应该在哪里设置它们?希望我很清楚。提前致谢

4

2 回答 2

0

我和 nburk 在一起,用这个简短的细节是不可能解决的。但是当您在 tableView 中使用自定义单元格时。每次创建单元格时,在 cellForRowAtIndexPath 方法中,您都可以使用 dispatch_async(dispatch_get_main_queue(), ^{......your code here for custom cell..... }); //用于更新 UI 我不确定,但是当您显示屏幕 UI 的线条没有按时更新时。

于 2015-06-05T07:35:41.363 回答
0

我建议你定义一个 UITableViewCell 的子类并在init/initWithCoder:方法中创建所有约束。

并且不要忘记正确地重复使用您的细胞。这样,您就不会一直重新创建单元格的约束。

编辑:看看下面的例子。

static NSString* const kCellIdentifier = @"CustomTableViewCellIdentifier";

@implementation CustomTableViewController

- (void)viewDidLoad
{
    [self.tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:kCellIdentifier];
}

- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    CustomTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    // configure your cell here
    return cell;
}

@end


@interface CustomTableViewCell: UITableViewCell
@end

@implementation CustomTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // add subviews and install constraints here. Don't forget to use contentView instead of cell when you install constraints.
    }

    return self;
}

@end
于 2015-07-21T08:58:00.707 回答