【问题标题】:UITableView - Sectioned Tableview drilling down into Children subviews then into a Detail viewUITableView - 分段的 Tableview 深入到子子视图然后进入详细视图
【发布时间】:2011-05-18 09:26:29
【问题描述】:

是否有人可以发布 pList 和 UITableView 代码以说明如何执行此操作?

基本上我想要一个从 pList 文件加载的分段表视图,它可以深入到子子视图并最终导致详细视图。即..

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

*::::::::: 饮料 ::::::::: *
- 啤酒
- - 米勒斯
- - - > 详细视图
- - 海尼肯
- - - > 详细视图
- 葡萄酒
- - 赤霞珠梅洛
- - - > 详细视图
- - 赤霞珠 Sav
- - - > 详细视图

【问题讨论】:

  • 这个问题在 2011 年会被认为过于宽泛,不知何故它逃脱了关闭。现在规则明显更严格了,幸运的是,这仍然是开放的。根据当今有效的发布指南,它过于宽泛。

标签: iphone objective-c ios uitableview plist


【解决方案1】:
@interface SectionsViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSDictionary *names;
NSArray *keys;
}
@property (nonatomic, retain) NSDictionary *names;
@property (nonatomic, retain) NSArray *keys;    
@end

现在,切换到 SectionsViewController.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

【讨论】:

  • “结构”是什么意思?是的,如果它有帮助,请接受它:)
  • 我更新了原始帖子以显示我需要设置并深入了解表格视图。这适用于您的代码吗?干杯:)
猜你喜欢
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-02
  • 1970-01-01
相关资源
最近更新 更多