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

标签 iphone xcode styles uitableview

我正在尝试将 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/

相关文章:

iphone - 在设备中测试时 SLComposeViewController 崩溃

ios - GMSMapView 中的倒多边形

ios - 有没有办法在 URL 方案中转到 "Settings"?

css - ie10样式表

ios - Tableview reloadRowsAtIndexPaths 获得 50% CPU 内存?

iphone - 循环计数器 - 最短方法

ios - XCode 使用不存在的 sqlite 数据库

ios - 为什么 playground 在 getter 结果前加上 "some"

安卓主题声明

javascript - 如何设置 Google Chrome 语音输入控件的麦克风样式