Possible Duplicate:
iPhone UITableView Sections
Basically guys trying two put the table into two different sections but whatever I try it doesn't seem to work, there is my code please can you tell me where I'm going wrong, examples would be greatly appreciated! No one has managed to solve this yet and I've been really stuck for a while. Thanks Sam Houghton.
#import <Foundation/Foundation.h>
@interface FirstLevelViewController : UITableViewController {
NSArray *controllers;
NSMutableArray *male;
NSMutableArray *female;
}
@property (nonatomic, retain) NSArray *controllers;
@property (nonatomic, retain) NSMutableArray *male;
@property (nonatomic, retain) NSMutableArray *female;
@end
#import "FirstLevelViewController.h"
#import "SecondLevelViewController.h"
#import "DisclosureDetailController.h"
#import "SecondVoiceController.h"
#import "ThirdVoiceController.h"
@implementation FirstLevelViewController
@synthesize controllers,male,female;
-(void)viewDidLoad {
self.title = @"Voices";
DisclosureDetailController *th = [DisclosureDetailController alloc];
th.title = @"First Voice";
[male addObject:th];
[th release];
SecondVoiceController *array2 = [SecondVoiceController alloc];
array2.title = @"Second Voice";
[male addObject:array2];
[array2 release];
ThirdVoiceController *array3 = [ThirdVoiceController alloc];
array3.title = @"Third Voice";
[female addObject:array3];
[array3 release];
self.controllers = male;
[female release];
[male release];
[super viewDidLoad];
}
-(void)viewDidUnload {
self.male = nil;
self.female = nil;
self.controllers = nil;
[super viewDidUnload];
}
-(void)dealloc {
[male release];
[female release];
[controllers release];
[super dealloc];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section){
case 0:
return [male count];
break;
case 1:
return [female count];
break;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *FirstLevelCell= @"FirstLevelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell] autorelease];
}
SecondLevelViewController *controller;
switch([indexPath section]){
case 0:
controller = [male objectAtIndex: [indexPath row] ];
break;
case 1:
controller = [female objectAtIndex: [indexPath row] ];
break;
}
cell.textLabel.text = controller.title;
cell.imageView.image = controller.rowImage;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
SecondLevelViewController *nextViewController = [self.controllers objectAtIndex:row];
[self.navigationController pushViewController:nextViewController animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
@end
Basically guys trying two put the table into two different sections but whatever I try it doesn't seem to work, there is my code please can you tell me where I'm going wrong, examples would be greatly appreciated! No one has managed to solve this yet and I've been really stuck for a while. Thanks Sam Houghton