Created
December 30, 2011 23:09
-
-
Save jonsterling/1541947 to your computer and use it in GitHub Desktop.
Configuring UITableViews with C99 array initialization!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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