forkingdog / UITableView-FDTemplateLayoutCell

Template auto layout cell for automatically UITableViewCell height calculating
MIT License
9.94k stars 2.01k forks source link

无法使用UITableViewCellStyleValue1风格的cell #272

Closed Andy0570 closed 7 years ago

Andy0570 commented 7 years ago

因为我在使用UITableViewCellStyleValue1的时候经常发生detailTextLabel文字长短不一致,而且文字太长就无法完全显示的情况,所以需要动态计算高度。 但是如果我要使用并创建UITableViewCellStyleValue1风格的cell,就必须在** tableView: cellForRowAtIndexPath:中注册重用cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 注册重用cell
    static NSString *tableViewCellStyleValue1 = @"UITableViewCellStyleValue1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCellStyleValue1];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:tableViewCellStyleValue1];
    }
    return cell;
}

但是你的文档中提及要么是 Storyboard 中的原型 cell,要么就是使用了 UITableView 的 -registerClass:forCellReuseIdentifier:-registerNib:forCellReuseIdentifier:其中之一的注册方法。 所以如果我在 viewDidLoad中注册cell用这个方法registerClass:forCellReuseIdentifier:创建出来的是默认UITableViewCellStyleDefault风格的cell,detailTextLabel是无法显示的。 希望得到你们的帮助!

OCer commented 7 years ago

好像对自带的cell是不行的,要自定义cell,我用自带的cell计算也出问题了

arkilis commented 7 years ago

这么说是必须要使用自定义的 Cell 咯?