简体   繁体   English

UItableviewcontroller不会在行中显示数据并创建额外的行

[英]UItableviewcontroller doesnt display data in rows and creates extra row

在此输入图像描述 在此输入图像描述

I have created UITableViewController . 我创建了UITableViewController I have a NSMutableArray with three records. 我有一个NSMutableArray有三个记录。 I have created a custom UITableViewCell class and linked it with TableViewCell . 我创建了一个自定义的UITableViewCell类并将其与TableViewCell链接。 But when running the program my tableview displays below output. 但是在运行程序时,我的tableview显示在输出下方。 There are only three records but table view shows 5 rows and all my data are showed in first row itself. 只有三个记录,但表视图显示5行,我的所有数据都显示在第一行本身。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
callRecordsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CallRecordsCell" forIndexPath:indexPath];
callRecords *record = [self.callRecordsDataController callRecordAtIndex:indexPath.row];
NSLog(@"Indexpath row now is %d",indexPath.row);
cell.callRecordOriginalDestinationLabel.text = record.originalDestination_Alias;
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"dd-MMM"];

cell.callRecordStartTime.text = [[NSString alloc]initWithString:[df stringFromDate:record.start_Time]];
cell.callRecordCallDuration.text = record.call_Duration;
return cell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"count is %d",[self.callRecordsDataController callRecordsCount]);
return [self.callRecordsDataController callRecordsCount];
}

DataController code DataController代码

-(NSUInteger)callRecordsCount{
    return [self.callRecordsList count];
}

- (callRecords *)callRecordAtIndex:(NSUInteger)index{
   return [self.callRecordsList objectAtIndex:index];
}

I found the problem.it was because of rendering issues in iphone7plus simulator.i ran the same project in other simulators it was displaying it correctly. 我找到了问题。因为iphone7plus模拟器中的渲染问题。我在其他模拟器中运行了相同的项目,它正确显示它。

!iphone7plus simulator !iphone7plus模拟器 iphone7模拟器

There are only three records but table view shows 5 rows and all my data are showed in first row itself.can somebody help?? 只有三个记录,但表视图显示5行,我的所有数据都显示在第一行本身。有人帮忙??

  1. First on all, I DO think the table is showing only 3 records. 首先,我认为该表只显示3条记录。
  2. Three records ARE NOT displaying in the same row. 三条记录不显示在同一行中。

My guess, 我猜,

  1. Back to the storyboard, I think you set the row height, separator and the layout constraints in the cell wrongly. 回到故事板,我认为您错误地设置了单元格中的行高,分隔符和布局约束。

Please screecap the storyboard and post your cell design. 请筛选故事板并发布您的单元格设计。

Also read this tutorial about creating custom cell with storyboard: https://www.appcoda.com/ios-programming-customize-uitableview-storyboard/ 另请阅读本教程,了解如何使用故事板创建自定义单元格: https//www.appcoda.com/ios-programming-customize-uitableview-storyboard/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM