Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Save the nib file and single-click BIDViewController.m. Look for the toggleControls: method that Xcode created for us and add the following code to it:
- (IBAction)toggleControls:(id)sender {
// 0 == switches index
if ([sender selectedSegmentIndex] == 0) {
leftSwitch.hidden = NO;
rightSwitch.hidden = NO;
doSomethingButton.hidden = YES;
}
else {
leftSwitch.hidden = YES;
rightSwitch.hidden = YES;
doSomethingButton.hidden = NO;
}
}
This code looks at the selectedSegmentIndex property of sender, which tells us which of the sections is currently selected. The first section, called switches, has an index of 0, a fact that we've written down in a comment so that when we later revisit the code, we know what's going on. Depending on which segment is selected, we hide or show the appropriate controls.