在UIView(UIView控制器)中加载多个表格

我一直在search整个互联网寻求帮助,但是我的问题几乎没有解决办法。 我试图得到一个喘息的项目是有点独特的(用户界面不完全遵循典型的规范)。

目前的发展环境:

  • xcode 4
  • 故事板,而不是笔尖

下面是我想要完成的一个图 – 所有在一个UIView控制器:

在这里输入图像说明

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

我肯定有经验的开发人员完全知道我的问题,或者即将要问什么。 我明白,一个静态的UITableView需要在一个tableview控制器,但我需要同时显示两个UItableView的,这意味着它必须在一个UIView。

我可以使界面看起来像我需要通过IB的方式,但是当试图编译和构build我收到的错误,需要UITableView的UITableViewController而不是一个UIView控制器。 我已经看到很多使用主从布局的例子,但唯一的规定是这个UITableview需要在这个视图中100%显示。

所以基本上,我要求的方向…但代码示例从来没有受到伤害! 谢谢100倍!

-Jonathan

UITableViewController只是一个专门devise用于显示全屏UITableView的专用UIViewController 。 它(相当)使用UITableViewController子类或UIViewController <UITableViewDataSource, UITableViewDelegate>子类来pipe理一个tableview。

因此,即使UITableViewController具有一些更特化的行为(自动创buildUITableView,如果它不存在,自动滚动显示键盘,将自身设置为它所pipe理的唯一UITableViewdelegatedataSource等),则可以使用标准UIViewController来pipe理一个UITableView并且是它的dataSource来填充它。

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


所以在你的情况下,你可以有一个UIViewController有两个IBOutlets ,每个tableView一个,唯一的UIViewController可以是两个 UITableViewsdataSource (和delegate )。 这不是问题。 只需要小心,然后在你的数据源方法来区分,如果你是第一个或第二个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; }