So ändern Sie den Stil eines UITableViewController programmgesteuert in Xcode

Ich versuche, ändern Sie den Stil eines UITableViewController zu Gruppen zusammengefasst. Ich weiß, Sie können dies tun, wenn das erstellen einer neuen Tabelle anzuzeigen, aber ich habe eine Klasse, die Sie erweitert UITableViewController, so dass ich nicht brauchen, um eine neue Tabelle anzeigen. Hier ist mein code:

#import "DetailViewController.h"
#import "NSArray-NestedArrays.h"

@implementation DetailViewController

@synthesize steak, sectionNames, rowControllers, rowKeys, rowLabels;

- (void)viewDidLoad {
    sectionNames = [[NSArray alloc] initWithObjects:[NSNull null], NSLocalizedString(@"General", @"General"), nil];
    rowLabels = [[NSArray alloc] initWithObjects:
             [NSArray arrayWithObjects:NSLocalizedString(@"Steak Name", @"Steak Name"), nil],
             [NSArray arrayWithObjects:NSLocalizedString(@"Steak Wellness", @"Steak Wellness"), NSLocalizedString(@"Steak Type", @"Steak Type"), NSLocalizedString(@"Other", @"Other"), nil]
             , nil];
    rowKeys = [[NSArray alloc] initWithObjects:
           [NSArray arrayWithObjects:@"steakName", nil],
           [NSArray arrayWithObjects:@"steakWellness", @"steakType", @"other", nil]
           , nil];


    //TODO: Populate row controllers array

    [super viewDidLoad];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [sectionNames count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    id theTitle = [sectionNames objectAtIndex:section];
    if ([theTitle isKindOfClass:[NSNull class]]) {
        return nil;
    }
    return theTitle;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [rowLabels countOfNestedArray:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"SteakCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
    }

    NSString *rowKey = [rowKeys nestedObjectAtIndexPath:indexPath];
    NSString *rowLabel = [rowLabels nestedObjectAtIndexPath:indexPath];

    cell.detailTextLabel.text = rowKey;
    cell.textLabel.text = rowLabel;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //TODO: Push editing controller onto the stack
} 
@end 
InformationsquelleAutor Mr. Pie Guy | 2012-08-11
Schreibe einen Kommentar