我想使用 uitableviews 深入了解 plist 以获得特定的学校。向下钻取是州->区->学校。我创建了一个 plist,但不能 100% 确定该结构是最好的。此外,我可以在第一个 tableview 上获得第一组活动信息,但不知道如何从那里开始。我是否需要为每个向下钻取(stateview、districtview、schoolview)创建一个表格视图,或者我可以重用一个通用表格视图,因为它们只是列表?以下是我到目前为止所拥有的。谢谢你的帮助。
PLIST
<plist version="1.0">
<array>
<dict>
<key>districts</key>
<dict>
<key>District 1</key>
<array>
<string>School 2</string>
<string>School 1</string>
</array>
<key>District 2</key>
<array>
<string>School 3</string>
<string>School 4</string>
</array>
</dict>
<key>state</key>
<string>South Dakota</string>
</dict>
<dict>
<key>districts</key>
<array>
<string>District 1</string>
<string>District 2</string>
</array>
<key>state</key>
<string>Arkansas</string>
</dict>
<dict>
<key>districts</key>
<array>
<string>District 3</string>
<string>District 4</string>
</array>
<key>state</key>
<string>New York</string>
</dict>
</array>
</plist>
这是我的视图控制器
#import "plistViewController.h"
@interface plistViewController ()
@end
@implementation plistViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
@synthesize content = _content;
-(NSArray *)content
{
if (!_content) {
_content = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]];
}
return _content;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.content count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [[self.content objectAtIndex:indexPath.row] valueForKey:@"state"];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
}
@end