I'm trying to display a message when the user chooses 2 values from a double component picker
.
In case the user’s choice was "High Fever" and "Strong Cough", use an Alert View to display a message indicating: 'you should do the PCR Test'.
In case the user’s choice was a selection of "High Fever" and "Medium Cough" or "Medium Fever" and "Strong Cough", display a message indicating: 'it is just a normal flu'.
In case of all other possible selections, display a message: 'Relax... Nothing to worry about!'
Here is the code below:
#import "FirstViewController.h"#define kFeverComponent 0#define kCoughComponent 1@interface FirstViewController ()@property (strong, nonatomic) NSArray *feverTypes;@property (strong, nonatomic) NSArray *coughTypes;@property (weak, nonatomic) IBOutlet UIPickerView *dependentPicker;@end@implementation FirstViewController- (void)viewDidLoad { [super viewDidLoad]; self.feverTypes = @[@"High Fever", @"Medium Fever", @"No Fever"]; self.coughTypes = @[@"Strong Cough", @"Medium Cough", @"No Cough"];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}- (IBAction)symptomsButtonPressed:(id)sender { NSInteger feverRow = [self.dependentPicker selectedRowInComponent: kFeverComponent]; NSInteger coughRow = [self.dependentPicker selectedRowInComponent: kCoughComponent]; NSString *fever = self.feverTypes[feverRow]; NSString *cough = self.coughTypes[coughRow]; NSString *message = [[NSString alloc] initWithFormat: @"You chose %@ and %@.", fever, cough]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Thank you for choosing" message:message preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil]; [alert addAction:action]; [self presentViewController:alert animated:YES completion:nil];}#pragma mark -#pragma mark Picker Data Source Methods- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 2;}- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component { if (component == kCoughComponent) { return [self.coughTypes count];} else { return [self.coughTypes count];}}#pragma mark Picker Delegate Methods- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component == kCoughComponent) { return self.coughTypes[row]; } else { return self.feverTypes[row];}}@end