多个原型单元显示固定高度

时间:2017-06-02 11:45:11

标签: ios objective-c uitableview storyboard row-height

我是IOS的新手,我正在尝试在UITableView中制作多个原型单元格,但总是得到相同大小的行,不知道为什么它的行为是这样的。我搜索了很多!但没有任何线索,任何帮助都会对我很有帮助。在此先感谢。This is the image for what I am doingthis is what I am getting as output

这是我的DataSource方法代码......

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
   (NSInteger)section
 {
    return 12;
 }

- (UITableViewCell *)tableView:(UITableView *)tableView 
   cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
     NSInteger count = indexPath.row;
     if(count == 0)
     {
         DetailPostCell *Cell1 = (DetailPostCell *)[tableView 
          dequeueReusableCellWithIdentifier:@"Cell1" 
            forIndexPath:indexPath];
       return  Cell1;
    }
    else
    {
         CommentCell *Cell2 = (CommentCell *)[tableView 
          dequeueReusableCellWithIdentifier:@"Cell2" 
            forIndexPath:indexPath];
         return Cell2;
     }
 }

2 个答案:

答案 0 :(得分:0)

您没有正确设置layoutconstraint。

如何吗

请务必在您的单元格中至少在一个插座中添加顶部和底部约束。就像这样。 enter image description here

和 在视图控制器的viewDidLoad.write这两行。

geolocator.reverse(query)

答案 1 :(得分:-1)

实现设置原型单元格高度的委托方法,在这种情况下,第一个单元格需要与其他单元格不同的高度。如果为每个单元格返回适当的高度,则单元格的内容会正确显示。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0) {
        return  //Desired hight of your first cell;
    }
    else {
        return  //Desired hight of your rest cells;
    }
}

result screen shot of comment mention below