使用情节提要为单元格创建约束,但cell.contentView.constraints.count为0。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell"];
cell.fd_enforceFrameLayout = NO;// why equals to 0
cell.item = self.items[indexPath.row];
NSLog(@"%ld", cell.contentView.constraints.count);
return cell;
}发布于 2015-09-16 17:22:01
尝试使用dequeuReusableCellWithIdentfier的forIndexPath版本。非indexPath版本返回一个没有size类的单元格,因为该单元格不是表的一部分。forIndexPath版本确实返回了一个具有size类的单元格,因为它从包含该单元格的表中继承了它。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell" forIndexPath:indexPath];
cell.fd_enforceFrameLayout = NO;// why equals to 0
cell.item = self.items[indexPath.row];
NSLog(@"%ld", cell.contentView.constraints.count);
return cell;
}然后,NSLog应该输出与您运行的size类的约束数量相匹配的count值。将size类作为调试的一部分打印出来是值得的。
https://stackoverflow.com/questions/32567009
复制相似问题