UITableView - секционированное табличное представление, детализирующее дочерние подвиды, затем детализированное представление - PullRequest
0 голосов
/ 18 мая 2011

Кто-нибудь может опубликовать код pList и UITableView о том, как это сделать?

По сути, я хочу загрузить секционированное табличное представление из файла pList, которое может детализировать дочерние дочерние представления и в конечном итоге привести к подробному виду. то есть ..

* ::::::::: Еда ::::::::: *
- Вход
- - Брускетта
- - -> Подробный вид
- - Чесночный хлеб
- - -> Детальный просмотр
- сеть
- - Стейк Рамп
- - -> Подробный вид
- - Куриная грудка
- - -> Детальный просмотр

* ::::::::: Напитки ::::::::: *
- пиво
- - Миллеры
- - -> Подробный вид
- - Heiniken
- - -> Подробный вид
- Вино
- - Каберне Мерло
- - -> Подробный вид
- - Каберне Сав
- - -> Подробный вид

1 Ответ

1 голос
/ 18 мая 2011
@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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...