2

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

目前的发展环境:

  • 代码 4
  • 故事板而不是笔尖

下面是我正在尝试完成的图表——全部在 UIView 控制器中:

在此处输入图像描述

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

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

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

所以基本上,我在问方向......但一个代码示例也没有伤害!谢谢你 100x 结束了!

-乔纳森

4

1 回答 1

5

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

因此,即使UITableViewController有一些更特殊的行为(如果 UITableView 不存在则自动创建,自动滚动以显示键盘,将自身设置为它管理的唯一的delegate和等),您可以使用标准来管理和是它来填补它。dataSourceUITableViewUIViewControllerUITableViewdataSource

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


因此,在您的情况下,您可以拥有一个UIViewController具有两个IBOutlets,每个一个tableView,并且唯一的UIViewController可以是两者dataSource(和delegate)。这不是问题。然后在您的数据源方法中小心区分您是返回第一个还是第二个数据,以便每次都提供正确的表。UITableViewsUITableView

@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;
}
于 2012-09-17T20:34:17.443 回答