重複の可能性:
iPhone UITableView セクション
基本的に、2 つのテーブルを 2 つの異なるセクションに分けようとしている人がいますが、何を試してもうまくいかないようです。私のコードがあります。どこが間違っているのか教えてください。例を教えていただければ幸いです。誰もこれを解決できず、私はしばらくの間本当に行き詰まりました。ありがとうサム・ホートン。
#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
基本的に、2 つのテーブルを 2 つの異なるセクションに分けようとしている人がいますが、何を試してもうまくいかないようです。私のコードがあります。どこが間違っているのか教えてください。例を教えていただければ幸いです。誰もこれを解決できず、私はしばらくの間本当に行き詰まりました。ありがとうサム・ホートン