首先:为什么不直接在占据整个屏幕的推送视图控制器上显示文件?对我来说似乎更直观。
如果你想用两个 tableView 来做,并假设它们使用动态单元格:
1,在你的视图控制器的 .h 文件中
像这样指定两个 tableView 属性:
@property (weak, nonatomic) IBOutlet UITableView *foldersTableView;
@property (weak, nonatomic) IBOutlet UITableView *filesTableView;
实现 UITableVIew 的两个委托协议
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
2、 将两个 UITableView 添加到您的 ViewController 中,然后...
- ...将您的 Outlets 链接到两个表格视图
- ...在属性检查器上,将foldersTableView 的Tag 设置为1,将filesTableView 的Tag 设置为2
- ...选择每个 UITableViews,转到 Connections Inspector 并将它们的两个委托方法(委托和数据源)链接到您的 ViewController(对于它们)
3、在你的 ViewController 的 .m 文件中实现 UITableView 的三个数据源方法,如下所示:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
if (tableView.tag == 1) {
return theNumberOfSectionsYouWantForTheFolderTableView;
} else {
return theNumberOfSectionsYouWantForTheFilesTableView;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView.tag == 1) {
return [foldersArray count];
} else {
return [filesArray count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 1) {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
return cell;
} else {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
return cell;
}
}
4、实现选择:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 1) {
//fill filesArray with the objects you want to display in the filesTableView...
[filesTableView reloaddata];
} else {
//do something with the selected file
}
}
希望我得到了正确的一切。如果您使用的是 XCode 4.4 之前的版本,请不要忘记 @synthesize .m 文件中的属性。