gpt4 book ai didi

ios - UITableView 单元格在单元格位于屏幕顶部之前不会绘制

转载 作者:行者123 更新时间:2023-11-29 04:46:45 25 4
gpt4 key购买 nike

我正在构建一个表,其中 UITableView 的每个单元格都是 UIViewController。我需要在表格的三行中显示三个不同的 UIViewController。我将每个单元格的行设置为与 UIViewController 的大小相匹配,因此每行都有不同的高度。

当应用程序首次启动时,仅显示第一个单元格中的 UIViewController。直到我滚动表格以使该行的顶部位于屏幕顶部时,下一行的内容才会显示。同样,如果我稍微向下滚动,使一行稍微偏离屏幕底部,当我向上滚动一点时,行内容就会消失。

这是我正在使用的代码。注意: Controller 是在viewdidload方法中创建的

我错过了什么?谢谢

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:      (NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;


switch(indexPath.section)
{
case 0:
{
[cell.contentView addSubview:patientInformationController.view];
break;
}
case 1:
{
[cell.contentView addSubview:labsController.view];
break;
}
case 2:
{
[cell.contentView addSubview:planController.view];
break;
}


default:
break;
}
}
return cell;
}

最佳答案

UITableViewController 是一个巨大的高级构造,用于有效管理整个屏幕的数据和 UI 对象。 UITableViewCell 是一个小型、高效、高度优化的 View 类,旨在尽快绘制和更新。

永远不要将 UIViewController 的 View 添加到 UITableViewCellcontentView 中。一些标签,一张图像,也许是一个小控件,例如 UISwitchUITextView

如果您还没有阅读过,请开始阅读 here .

如果您想将 View Controller (patentInformationController、labsController)与 TableView 的特定行相关联,正确的方法是将该行的单元格标签设置为人类可读的字符串,例如@“Patient Information”,或@“Labs”,然后,当选择该行时,使用 UINavigationController 推送正确的 View Controller 。

UINavigationController 管理 UIViewController 堆栈。 UIViewController 管理单个连贯的界面,通常由一堆协作 View 组成。 UITableViewController 是 UIViewController 的子类,它管理单个 UITableView。 UITableView 是一个专门用于快速呈现和呈现表格数据的类,根据您提供的委托(delegate)和数据源将其组织成部分和行。 UITableView 的功能之一是在用户选择 UITableView 的一行时通知其委托(delegate),从而允许委托(delegate)通过 UINavigationController 呈现一个新的 UIViewController,以便向用户呈现更多细节和功能。

希望这有帮助。开始阅读。

关于ios - UITableView 单元格在单元格位于屏幕顶部之前不会绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com