我创建了一个具有分组样式的表格 View 。我已将此表添加到 UIScrollView 的 subview 中。我根据表的行数计算了表的大小。所以tableView没有滚动。我将能够看到所有的细胞。
表格第一次正常工作并显示所有单元格。但我的问题是,每当我导航到下一页并返回并重新加载该表时,它只是渲染和重绘分配的单元格。被重用的单元格不会被重绘。 tableView:cellForRowAtIndexPath: 也不会为这些单元格调用。
我怀疑,由于表格 View 的滚动被禁用,重用单元格的 cellForRowAtIndexPath 方法不会被调用,因此它们不会被渲染。
我通过以下方式创建了tableView
m_TravellerDetailTable = [[UITableView alloc] initWithFrame: CGRectMake( 2.0f, 0, 315.0f, 370 ) style: UITableViewStyleGrouped ];
float height = (tableViewCellHeight * [travellersArray count]);
m_TravellerDetailTable.frame = CGRectMake(2, 0, 315, height);
[m_TravellerDetailTable setBounces: NO];
[m_TravellerDetailTable setScrollEnabled: NO];
[m_BaseScrollView addSubview: m_TravellerDetailTable];
UITableViewDelegate 方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [travellersArray count];
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return tableViewCellHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[TravellerDetailCustomCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
TravellerDetailCustomCellView *customCell = (TravellerDetailCustomCellView *)cell;
[customCell.textLabel setText:[travellerInfoFromDetailForm objectForKey:@"DOB"]];
}
此快照显示了 uitableview 渲染所有单元格
快照显示 uitableview 仅渲染到“Adult 8”单元格。此后,表格不再渲染剩余的单元格。
最佳答案
它正在渲染,但你的框架太小,表格 View 被切断。
你应该删除
[m_TravellerDetailTable setBounces: NO];
[m_TravellerDetailTable setScrollEnabled: NO];
关于objective-c - UITableView 重用未绘制的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422752/