UITableView - 分段表视图向下钻取到子视图,然后钻取到详细信息视图



有人能够发布有关如何执行此操作的pList和UITableView代码吗?

基本上,我想要一个从pList文件加载的分段表视图,它可以向下钻取到子子视图并最终导致详细信息视图。

*:::::::::食物:::::::::*
- 主菜
- - 布鲁斯切塔
- - -> 详细视图
- - 大蒜面包
- - -> 详细信息视图
-电源
- - 牛排臀
部 - - -> 详细视图
--鸡胸肉
- - -> 详细信息视图

*:::::::::饮料:::::::::*
-啤酒
--米勒
- - -> 详细视图
- - 海尼根
- - -> 详细视图
-酒
- - 赤霞珠梅洛
- - -> 详细视图
- - 赤霞珠
- - -> 详细信息视图

@interface SectionsViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSDictionary *names;
NSArray *keys;
}
@property (nonatomic, retain) NSDictionary *names;
@property (nonatomic, retain) NSArray *keys;    
@end

现在,切换到 SectionViewController.m,并将以下代码添加到该文件的开头:

#import "SectionsViewController.h"
@implementation SectionsViewController
@synthesize names;
@synthesize keys; 
- (void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"YOURpLISTfILE" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.names = dict; [dict release];
NSArray *array = [[names allKeys] sortedArrayUsingSelector: @selector(compare:)];
self.keys = array;
}

并在文件末尾的 @end 声明上方添加以下代码:

#pragma mark 
#pragma mark Table View Data Source Methods - 
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
return [keys count];
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:     (NSInteger)section
 { NSString *key = [keys objectAtIndex:section]; NSArray *nameSection = [names objectForKey:key];
 return [nameSection count];
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
 NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section]; NSArray *nameSection = [names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SectionsTableIdentifier;
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease];
}
cell.textLabel.text = [nameSection objectAtIndex:row]; return cell;
(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{
 NSString *key = [keys objectAtIndex:section]; return key;
}
@end

最新更新