UITableview不显示所有数组记录

时间:2015-10-27 05:43:11

标签: ios objective-c arrays uitableview storyboard

我正在尝试使用Storyboard自定义表显示TableView记录,但tableview仅显示数组的第一行而不显示其他行。

数组中的数据是:

  

< __ NSArrayM 0x7a8cf910>(   零件运输:包括,第二天上午10:30 LST-GENERAL-US - 44,   非使用情况,   M-F 0700-2200-US,   0328609 MSA - 2012- 0   )   ,

     

< __ NSArrayM 0x7a8cf940>(   1小时旅行前后息差覆盖范围M-F 0800-2100-US - 45,   非使用情况,   M-F 0700-2200-US,   0328609 MSA - 2012- 0   )

我用来显示cellForRowAtIndexPath的代码如下:

    static NSString *TableIdentifier = @"CellIdent";

    UITableViewCell *cell;
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if(indexPath.row < [entitlements count])
    {
        finalDataArray = [entitlements objectAtIndex:indexPath.row];
    }
    UILabel *firstRowLabel = [[UILabel alloc] init];
   firstRowLabel.frame = CGRectMake(10, 0, 250, 54);
   firstRowLabel.textAlignment = NSTextAlignmentCenter;
   firstRowLabel.text =  [finalDataArray objectAtIndex:0];
   firstRowLabel.textColor = [UIColor blackColor];
   firstRowLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
   firstRowLabel.backgroundColor=[UIColor clearColor];
   [cell.contentView addSubview:firstRowLabel];

    UIImageView *seperator1 = [[UIImageView alloc]initWithFrame:(CGRectMake(251, 0, 1, 47))];
   seperator1.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"table-header-separators.png"]];
   [cell.contentView addSubview:seperator1];

    UILabel *secondRowLabel = [[UILabel alloc] init];
   secondRowLabel.frame = CGRectMake(252, 0, 300, 54);
   secondRowLabel.textAlignment = NSTextAlignmentCenter;
   secondRowLabel.text =  [finalDataArray objectAtIndex:1];
   secondRowLabel.textColor = [UIColor blackColor];
   secondRowLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
   secondRowLabel.backgroundColor=[UIColor clearColor];
   [cell.contentView addSubview:secondRowLabel];       

    UIImageView *seperator2 = [[UIImageView alloc]initWithFrame:(CGRectMake(552, 0, 1, 47))];
   seperator2.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"table-header-separators.png"]];
   [cell.contentView addSubview:seperator2];

   UILabel *thirdRowLabel = [[UILabel alloc] init];
   thirdRowLabel.frame = CGRectMake(553, 0,280 , 54);
   thirdRowLabel.textAlignment = NSTextAlignmentCenter;
   thirdRowLabel.text =  [finalDataArray objectAtIndex:2];
   thirdRowLabel.textColor = [UIColor blackColor];
   thirdRowLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
   thirdRowLabel.backgroundColor=[UIColor clearColor];
   [cell.contentView addSubview:thirdRowLabel];

    UIImageView *seperator3 = [[UIImageView alloc]initWithFrame:(CGRectMake(840, 0, 1, 47))];
   seperator3.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"table-header-separators.png"]];
   [cell.contentView addSubview:seperator3];

    UILabel *fourthRowLabel = [[UILabel alloc] init];
   fourthRowLabel.frame = CGRectMake(841, 0,180 , 54);
   fourthRowLabel.textAlignment = NSTextAlignmentCenter;
   fourthRowLabel.text =  [finalDataArray objectAtIndex:3];
   fourthRowLabel.textColor = [UIColor blackColor];
   fourthRowLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
   fourthRowLabel.backgroundColor=[UIColor clearColor];
   [cell.contentView addSubview:fourthRowLabel];

但它只显示array1的前4个值而不显示下一个4。

你能指导一下这可能是什么问题吗?

由于

2 个答案:

答案 0 :(得分:0)

解决方案在于实现UITableView,这些是实现UITableView时要记住的事项:

  • 添加协议 UITableViewDelegate UITableViewDataSource
  • 添加两个数据源方法: tableView:numberOfRowsInSection tableView:cellForRowAtIndexPath
  • 确保 Connections Inspector
  • 中的连接 Outlets (委托和数据源)
  • 不要忘记在故事板中命名相应的UITableViewCell标识符(必须与 cellForRowAtIndexPath 中的标识符相同)

答案 1 :(得分:0)

检查 numberOfRowsInSection numberOfSectionsInTableView ,并根据它使用 indexPath.row indexPath.section 。< / p>