views:

65

answers:

0

answer.h:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "operator.h"

@interface answer : NSObject/* Specify a superclass (eg: NSObject or NSView) */ {
    IBOutlet operator *operator1;
    IBOutlet operator *operator2;
IBOutlet UILabel *answerLabel;
IBOutlet UISegmentedControl *operation;
}
- (IBAction)compute:(id)sender;
@end

answer.m:

#import "answer.h"

@implementation answer
- (IBAction)compute:(id)sender {

int selected = operation.selectedSegmentIndex;

switch (selected) {
    case 0:
        answerLabel.text = [NSString stringWithFormat:@"%d", (int)[operator1 number] + (int)[operator2 number]];
        break;
    case 1:
        answerLabel.text = [NSString stringWithFormat:@"%d", (int)[operator1 number] - (int)[operator2 number]];
        break;
    case 2:
        answerLabel.text = [NSString stringWithFormat:@"%d", (int)[operator1 number] * (int)[operator2 number]];
        break;
    case 3:
        answerLabel.text = [NSString stringWithFormat:@"%d", (int)[operator1 number] / (int)[operator2 number]];
        break;
    default:
        break;
}

}
@end

The problem I am having is that the selectedSegmentIndex always equals 0.