UITableView无法在模拟器中正确显示内容(视网膜4英寸)

时间:2013-12-17 12:36:26

标签: ios objective-c uitableview uistoryboard

我已经设置了三个原型单元,如下面的截图所示。但是当我运行应用程序时,标签和imageView等所有元素都没有正确显示。我在故事板中的原型单元格中设计了这些东西,使用拖动和将适当的元素放在所需的位置并且没有添加任何代码,例如heightForRow。我还检查了为Retina 4英寸设置的模拟指标。我做错了什么?

设计如下。

prototype cell

以下显示在模拟器上。

display

3 个答案:

答案 0 :(得分:2)

正确实施heightForRowAtIndexPath:并检查您的委托配置(tblview.delegate = self)

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
      return row1Height;
   else if(...).
   .
   .
   .
   else 
      return defaultHeight;

}

答案 1 :(得分:0)

您可以在委托方法中返回适当的行大小吗?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return yourHeight;
 }

答案 2 :(得分:-1)

试试这样:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier1 = @"Cell1";
    static NSString *CellIdentifier2 = @"Cell2";
    static NSString *CellIdentifier3 = @"Cell3";



    // Configure the cell...
    if([indexPath row] == 0)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1 forIndexPath:indexPath];
        //cell.textlabel = @"YourText";
        //
    }

    if([indexPath row] == 1)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath];
        //cell.textlabel = @"YourText";
        //
    }

    if([indexPath row] == 2)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3 forIndexPath:indexPath];
        //cell.textlabel = @"YourText";
        //
    }
相关问题