gpt4 book ai didi

iphone - 如何在 Xcode 中以编程方式更改 UITableViewController 的样式

转载 作者:行者123 更新时间:2023-12-03 20:21:53 24 4
gpt4 key购买 nike

我正在尝试将 UITableViewController 的样式更改为分组。我知道您可以在创建新的 TableView 时执行此操作,但我有一个扩展 UITableViewController 的类,因此我不需要创建新的 TableView 。这是我的代码:

#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

最佳答案

- (instancetype)init
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
}
return self;
}

关于iphone - 如何在 Xcode 中以编程方式更改 UITableViewController 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11918408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com