sai*_*esh 2 storyboard uitableview ios5 xcode4.2
在我的iPad应用程序故事板设计中,添加了两个表视图.
一个表视图用于显示文件夹名称,另一个表视图用于显示文件名.当选择文件夹表格视图单元格时,所选文件夹内的文件需要显示在另一个表格视图(文件表格视图)中.
我的问题是
我很困惑
ViewController?或者是否可以在ViewController以外的自定义类中为每个表视图添加数据源和委托?和
请帮忙 !
首先:你为什么不在推出的viewController上显示文件,它占用了整个屏幕?对我来说似乎更直观.
如果你想用两个tableViews做,并假设他们使用动态单元格:
1,在视图控制器的.h文件中
指定两个tableView属性,如下所示:
@property (weak, nonatomic) IBOutlet UITableView *foldersTableView;
@property (weak, nonatomic) IBOutlet UITableView *filesTableView;
Run Code Online (Sandbox Code Playgroud)
实现UITableVIew的两个委托协议
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
Run Code Online (Sandbox Code Playgroud)
2,将两个UITableView添加到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;
}
}
Run Code Online (Sandbox Code Playgroud)
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
}
}
Run Code Online (Sandbox Code Playgroud)
希望我能正确地得到一切.@synthesize如果您使用的是pre XCode 4.4,请不要忘记.m文件中的属性.
| 归档时间: |
|
| 查看次数: |
2434 次 |
| 最近记录: |