开发者

UITableView - Sectioned Tableview drilling down into Children subviews then into a Detail view

开发者 https://www.devze.com 2023-03-07 03:40 出处:网络
Is anyone able to post a pList and UITableView code on how to do this? Basically I want a Sectioned Tableview loaded from a pList file, that can drill down into children sub views and eventually lead

Is anyone able to post a pList and UITableView code on how to do this?

Basically I want a Sectioned Tableview loaded from a pList file, that can drill down into children sub views and eventually lead into a Detail View. ie..

*::::::::: Food ::::::::: *

- Entree

- - Bruschetta

- - - > Detail view

- - Garlic Bread

- - - > Detail View

- Mains

- - Steak Rump

- - - > Detail view

- - Chicken Breast

- - -开发者_运维技巧 > Detail View

*::::::::: Drinks ::::::::: *

- Beer

- - Millers

- - - > Detail view

- - Heiniken

- - - > Detail view

- Wine

- - Cabernet Merlot

- - - > Detail view

- - Cabernet Sav

- - - > Detail view


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

Now, switch over to SectionsViewController.m, and add the following code to the beginning of that file:

#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;
}

And add the following code at the end of the file, just above the @end declaration:

#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
0

精彩评论

暂无评论...
验证码 换一张
取 消