Skip to content

Instantly share code, notes, and snippets.

@jonsterling
Created December 30, 2011 23:09
Show Gist options
  • Save jonsterling/1541947 to your computer and use it in GitHub Desktop.
Save jonsterling/1541947 to your computer and use it in GitHub Desktop.
Configuring UITableViews with C99 array initialization!
// Define your table view's sections
typedef enum {
kTitleSection = 0,
kGoalSection,
kNumberOfSections
} NESTemplateEditTableSections;
// Make configuration arrays indexed against table sections.
// It's safe to reorder the original enum!
static NSString * const kCellIdentifiers[kNumberOfSections] = {
[kTitleSection] = @"AccomplishmentTitleCell",
[kGoalSection] = @"AccomplishmentGoalCell"
};
static UITableViewCellSelectionStyle const kCellSelectionStyles[kNumberOfSections] = {
[kTitleSection] = UITableViewCellSelectionStyleNone,
[kGoalSection] = UITableViewCellSelectionStyleBlue
};
static UITableViewCellAccessoryType const kCellAccessoryTypes[kNumberOfSections] = {
[kGoalSection] = UITableViewCellAccessoryDisclosureIndicator
};
// If you can't initialize an array statically (like if you need localized strings),
// just initialize it separately.
static NSString *kLocalizedSectionTitles[kNumberOfSections];
__attribute__((constructor)) static void __InitLocalizedSectionTitles()
{
@autoreleasepool {
kLocalizedSectionTitles[kTitleSection] = NSLocalizedString(@"What have you accomplished?", nil);
kLocalizedSectionTitles[kGoalSection] = NSLocalizedString(@"Category", nil);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment