Я следовал учебному пособию здесь и задавался вопросом, как сделать таблицу сгруппированной.
например:
group1 содержит Subview One и Subview Two
group2 содержит Subview Three
Я переключил тип в конструкторе интерфейсов, но это показывает только одну группу.
Спасибо,
Адам
Sidenote * Я совершенно новый в цели c, отсюда и учебник.
EDIT
Я подумал, что было бы полезно добавить код
#import "RootViewController.h"
#import "SubViewOneController.h"
#import "SubViewTwoController.h"
@implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
-(void)awakeFromNib {
views = [[NSMutableArray alloc] init];
SubViewOneController *subViewOneController = [[SubViewOneController alloc] init];
SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init];
//Subview 1
subViewOneController.title = @"Subview One";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview One", @"title",
subViewOneController, @"controller",
nil]];
[subViewOneController release];
//Subview 2
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = @"Subview Two";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview Two", @"title",
subViewTwoController, @"controller",
nil]];
[subViewOneController release];
//Subview 3
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = @"Subview Three";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview Three", @"title",
subViewOneController, @"controller",
nil]];
[subViewOneController release];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
self.title = @"Basic Navigation";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [views count];
}
//
//I think it goes somewhere in here
//
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier];
}
cell.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
- (void)dealloc {
[views dealloc];
[super dealloc];
}
@end