小编bla*_*ckp的帖子

UITableView动态单元格高度仅在某些滚动后才能正确显示

我有一个使用自动布局在故事板中定义UITableView的自UITableViewCell定义.细胞有几条多线UILabels.

UITableView出现要正确计算单元格高度,但在最初的几个细胞高度不正确的标签之间的分歧.滚动一下后,一切都按预期工作(即使是最初不正确的单元格).

- (void)viewDidLoad {
    [super viewDidLoad]
    // ...
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"TestCell"];
    // ...
    // Set label.text for variable length string.
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

有什么我可能会遗漏,导致自动布局在前几次无法完成其工作吗?

我已经创建了一个演示此行为的示例项目.

示例项目:首次加载时示例项目的表格视图顶部. 示例项目:向下滚动和备份后的相同单元格.

uitableview ios autolayout ios8 ios-autolayout

107
推荐指数
9
解决办法
5万
查看次数

表体不占用全表宽度

我正在使用twitter bootstrap进行响应式设计,其中包含一个包含四列的表.我希望表列的宽度相等,所以我设置td width为25%.

我认为表行将从表中继承它们的大小,然后表格单元格将是其中的四分之一.当设备宽度为768px或更高时,这似乎有效.当设备宽度较小时,行的大小将根据最大单元格中的文本进行调整,而不是父表的大小.

我在下面添加了一些示例代码,在不同元素上使用背景着色来突出显示错误(通过水平调整窗口大小来显示).错误以黄色突出显示(基础表颜色可见).

实例:http://pastehtml.com/view/cqrwl31z2.html

我在Chrome和Safari中测试过.

<!DOCTYPE html>
<html>
  <head>
    <title>Table Test</title>
    <!-- Bootstrap -->
    <link href="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
    <script type="text/javascript" src="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        td, th { width: 25% !important; }
        table { background-color: yellow; }
        tr { background-color: gray; }
        th { background-color: aqua; }
        td:nth-child(1) { background-color: red; }
        td:nth-child(2) { background-color: green; }
        td:nth-child(3) { background-color: blue; }
        td:nth-child(4) { background-color: purple; }
    </style>
  </head>
  <body>
    <div class="container"> …
Run Code Online (Sandbox Code Playgroud)

css html5 twitter-bootstrap

6
推荐指数
1
解决办法
2万
查看次数