gpt4 book ai didi

ios - 在 UIView 中加载多个 TableView (UIView Controller )

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:50 25 4
gpt4 key购买 nike

我一直在整个互联网上寻找帮助,但是对于我手头的问题几乎没有解决方案。我试图了解一下我的项目有点独特(UI 并不完全遵循典型规范)。

当前开发环境:

  • xcode 4
  • Storyboard而不是 Nib

下面是我正在努力完成的图表——全部在 UIView Controller 中:

enter image description here

  • UIView为浅灰色背景
  • UITableView 1 - 这是一个静态的(或者它可以是动态的,那是另一个挑战)UITableview,它将包含不同的数字计算值
  • UITableView 2 - 这是一个 UITableview,每次运行时都会保存计算结果。
  • UIImageView 1 - 这是一个计算图像示例(我已经弄明白了)

我确信有经验的开发人员完全了解我的问题,或者我要问的问题。我知道静态 UITableView 需要在 tableview Controller 中,但我需要同时显示两个 UItableView,这意味着它必须在 UIView 中。

我可以通过 IB 使界面看起来像我需要的那样,但是在尝试编译和构建时我收到错误,要求 UITableView 位于 UITableViewController 而不是 UIView Controller 内。我见过许多使用主从布局的示例,但唯一的规定是此 UITableview 需要在该 View 中 100% 的时间显示。

所以基本上,我是在寻求方向……但是代码示例也无妨!谢谢 100x 结束了!

-乔纳森

最佳答案

UITableViewController只是一个专门的UIViewController专为全屏显示而设计UITableView秒。它(相当)等同于使用 UITableViewController子类或 UIViewController <UITableViewDataSource, UITableViewDelegate>管理 tableview 的子类。

所以即使UITableViewController有一些更特殊的行为(如果 UITableView 不存在则自动创建它,自动滚动它以显示键盘,将自己设置为 delegatedataSource 它管理的唯一 UITableView 等),您可以使用一个标准UIViewController管理 UITableView成为它的dataSource填充它。

这甚至是一种管理不全屏显示的 TableView 的方法(因为 UITableViewController 期望它的 view 属性直接是它管理的 UITableView,而不是它的主视图的 subview 或其他任何东西,并且因此期望 UITableView 占据整个屏幕,与使用 UIViewController 相反,它有一个 UITableView 作为其 view 的自定义大小的子类)


所以在你的情况下,你可以有一个 UIViewController有两个IBOutlets , 每个人一个 tableView ,以及独一无二的 UIViewController可以是 dataSource (和 delegate )两者 UITableViews .那不是问题。然后在你的数据源方法中小心区分你是为第一个还是第二个返回数据UITableView每次都提供正确的表格。

@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) IBOutlet UITableView* masterTableView;
@property (nonatomic, retain) IBOutlet UITableView* detailsTableView;
@end

@implementation MyViewController
@synthesize masterTableView = _masterTableView;
@synthesize detailsTableView = _detailsTableView;

// Proper memory mgmt not shown here:
// - don't forget to set self.masterTableView and self.detailsTableView to nil in viewDidUnload
// - and to release _masterTableView and _detailsTableView in your dealloc method

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell;
if (tableView == self.masterTableView)
{
static NSString* kMasterCellIdentifier = @"MasterCell";
cell = [tableView dequeueReusableCellWithIdentifier:kMasterCellIdentifier];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithReuseIdentiier:kMasterCellidentifier] autorelease];
// do some configuration common to all your master cells
}
// configure the rest of your cell for each property that is different from one cell to another
}
else if (tableView == self.detailsTableView)
{
// Do exactly the same principle, but for the cells of your "details" TableView
}
return cell;
}

关于ios - 在 UIView 中加载多个 TableView (UIView Controller ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12466428/

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