2014-02-25 230 views
3

我有一个相当复杂的形式正在编排在UITableView。这种形式有一些UICollectionView表视图细胞内,也有一些采摘,显示了它以同样的方式在日历应用:查看更改UITableView更新

Image

现在我做这在我的应用程序时,该UICollectionView之一,我有得到比它是如何开始高 - 它不断地去(我加了红色边框,以确保它是正在调整的UICollectionView):

Image

我试着调试UICollectionView视图属性,但它永远不会改变(它是吸气剂/ setter不会超过我的预期) - 尽管当我在cellForRowAtIndexPath上打印它时,它确实显示了调整大小。有什么办法可以更好地调试,或者有人处于相同的情况?

谢谢!

代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//self.campos is a dictionary with sections and rows stored 
    NSMutableArray *infoCampos = [[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"]; 
NSDictionary *infoCampo = [infoCampos objectAtIndex:indexPath.row]; 

if ([[infoCampo objectForKey:@"nome"] isEqualToString:@"dosePorComprimido"]) { 
    //Remove picker cell if finds it 
    for (infoCampo in infoCampos) { 
     if ([infoCampo objectForKey:@"view"] == self.dosagemMedicamento.view) { 
      [infoCampos removeObject:infoCampo]; 
      [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic]; 
      [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
      return; 
     } 
    } 

    //Insert new cell 
    infoCampo = [infoCampos objectAtIndex:indexPath.row]; 
    [infoCampos addObject:@{@"tipo":@5, @"view":self.dosagemMedicamento.view, @"nome":[infoCampo objectForKey:@"nome"]}]; 
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic]; 
    [self.dosagemMedicamento.view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[pickerDosagem]|" options:0 metrics:nil views:@{@"pickerDosagem":self.dosagemMedicamento.view}]]; 
} 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row]; 
    UIView *view; 

    if ([infoCampo objectForKey:@"view"]) { 
     view = (UIView *) [infoCampo objectForKey:@"view"]; 
     return view.frame.size.height; 
    } 

    return 44.0f; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: 

(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell; 
    NSMutableDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row]; 
    UIView *view; 

cell = [tableView dequeueReusableCellWithIdentifier:[[infoCampo objectForKey:@"nome"] stringByAppendingString:@"ViewLinhaCellView"] forIndexPath:indexPath]; 

     view = [cell viewWithTag:1]; 

     [view addSubview:[infoCampo objectForKey:@"view"]]; 

return cell; 
} 

编辑:忘了提,我不会更新与reloadData表视图,但与reloadRowsAtIndexPaths和reloadSections只有所需的部分/行。所以这使得它更加怪异,因为我没有重新加载特定的部分。

编辑2:添加的数据源电子委托代码

+0

张贴您的表格视图数据源代码。它似乎是你回到了那个牢房的高度。检查你的heightforcell方法,并确保你的单元格返回适当的值 – CoolMonster

+0

我知道 - 我的heighForRowAtIndexPath只返回子视图的高度,所以问题是这个子视图(UICollectionView)正在调整大小,单元格也是如此。 – dccarmo

+0

你可以发布代码吗?没有代码示例就很难说出什么问题。 – Austin

回答

2

我相信你的问题是在这里,在tableView:heightForRowAtIndexPath:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row]; 
    UIView *view; 

    if ([infoCampo objectForKey:@"view"]) { 
     view = (UIView *) [infoCampo objectForKey:@"view"]; 
     return view.frame.size.height; 
    } 

    return 44.0f; 
} 

视图的实现可能得到通过自动布局或它的自动尺寸调整面具。这里没有足够的信息来说明原因,但表格视图和自动布局可能会有一些有趣的行为。我建议刚回来,你设置的高度,而不是从视图中获得高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row]; 
    UIView *view; 

    if ([infoCampo objectForKey:@"view"]) { 
     if ([infoCampo objectForKey:@"viewHeight"]) { 
      return [[infoCampo objectForKey:@"viewHeight"] floatValue]; 
     } else { 
      return 216.0f; 
     } 
    } 

    return 44.0f; 
} 

viewHeight键允许您指定每个单元的视图定制的高度,但这种实现也返回默认高度(这恰好是拾取器视图的标准高度。

+0

好主意,奥斯汀。我想我可能会这样做,尽管我很想知道调整大小的原因。谢谢! – dccarmo

+1

只是一个建议来检查,如果视图是从一个笔尖加载的:当您创建一个笔尖时,即使该笔尖使用自动布局,该视图也会有一个自动识别屏蔽集。尝试将视图的'autoresizingMask'属性设置为'UIViewAutoresizingNone'。 – Austin

+0

即使我没有从笔尖加载它,设置该属性解决!你摇滚!但是,你能详细说明autoresizingMask是如何工作的吗?为什么它受到UITableView重载的影响?非常感谢你 – dccarmo