UITableViewController
只是专门UIViewController
为全屏显示而设计UITableView
的。(相当)等价于使用UITableViewController
子类或UIViewController <UITableViewDataSource, UITableViewDelegate>
子类来管理 tableview。
因此,即使UITableViewController
有一些更特殊的行为(如果 UITableView 不存在则自动创建,自动滚动以显示键盘,将自身设置为它管理的唯一的delegate
和等),您可以使用标准来管理和是它来填补它。dataSource
UITableView
UIViewController
UITableView
dataSource
这甚至是一种管理不占据全屏的表格视图的方法(因为UITableViewController
期望它的view
属性直接是UITableView
它管理的,而不是其主视图的子视图或其他任何东西,因此期望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;
}