gpt4 book ai didi

objective-c - UIViewController 用于 UITableView tableHeaderView

转载 作者:太空狗 更新时间:2023-10-30 03:54:44 28 4
gpt4 key购买 nike

我的问题本质上主要是架构问题。我正在使用 UITableViewController 来显示内容列表。没什么大不了的,很标准。但是,tableHeaderView 包含大量功能。有几个点击目标,它会动画,并且显示会根据用户交互而变化。目前,我有一个自定义子类 UIView 处理大部分显示逻辑,并通过委托(delegate)协议(protocol)路由回 UITableViewController 以执行。

随着更多功能被添加到 tableHeaderView,我觉得我的 UITableViewController 变得有点杂乱和冗长。因此,我很好奇创建一个子类 UIViewContoller 并将其 view 设置为我的 UITableViewControllertableHeaderView 是否有意义>?如果这样做,我会更多地分离关注点,并且可以在我的新“UIViewController”中包含几乎所有的逻辑,我猜我仍然需要通过两个 viewController 之间的委托(delegate)来路由一些通信。

从架构的角度来看,这是否有意义?或者我应该继续为所有逻辑使用现有的 UITableViewController 吗?

** 编辑 **

例如,这段代码放在我的 UITableViewController 中是否有意义?

- (void)addHeader
{
myCustomHeaderViewController *hvc = [[myCustomHeaderViewController alloc] init];
//Assume the view for hvc is set up w/re to sizing, etc.
self.tableView.tableHeaderView = hvc.view
}

最佳答案

是的,你可以这样做,从 iOS5 开始,你有 Containment View Controllers,所以在一个 View Controller 中你可以添加几个子 View Controller,它们将一起工作。

您可以像这样在单独的 View Controller 中将标题 View 添加为 UIViewController 并将 TableView 添加为 UITableViewController:

- (void) addViewController: (UIViewController*)content;
{
[self addChildViewController:content];
content.view.frame = [self frameForController];
[self.view addSubview:self.currentClientView];
}

在这里您可以找到如何使用它们的指南:

Creating Custom Container View Controllers

关于objective-c - UIViewController 用于 UITableView tableHeaderView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18876530/

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