+// This method really belongs somewhere else, but the whole sections mechanism is broken and needs something to
+// encapsulate it *extremely* badly. :( Anyone up for writing something to make it slightly more sane?
+- (void) onSwitch:(id)sender {
+ [self _setVisibleState:[switch_ isOn] forSection:basic_];
+
+ for (Section *section in [delegate_ allSections]) {
+ NSString *basic = [section name];
+
+ static Pcre title_r("^(.*?) \\((.*)\\)$");
+ if (title_r(basic)) {
+ // If you turn off or on a top-level section, do the same to all its subsections.
+ if (base_ == nil && [section_ isEqual:title_r[1]]) {
+ [self _setVisibleState:[switch_ isOn] forSection:basic];
+ }
+ } else {
+ // If you turn on a subsection, make sure it's top-level section is on.
+ if ([switch_ isOn] && base_ != nil && [base_ isEqual:basic]) {
+ [self _setVisibleState:YES forSection:basic];
+ }
+ }
+ }
+
+ [delegate_ reloadData];
+}
+