So I’m trying to create an iphone app that does simple temperature conversion and when I run the code enter my number and hit submit nothing is displayed. I can’t seem to find the problem here is my header file
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UISegmentedControl *convtype;
@property (weak, nonatomic) IBOutlet UITextField *inputtemp;
@property (weak, nonatomic) IBOutlet UIButton *submit;
@property (weak, nonatomic) IBOutlet UILabel *outputtemp;
@end
Basically I have a UISegmentedController to select which conversion to do (0 is c to f and 1 is f to c)
I have a text field inputtemp for the temperature to convert. Submit is the submit button and a UIlabel outputtemp is where I want the result to be displayed.
Not quite sure where this is going wrong here is the rest of my code in the .m file
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize convtype;
@synthesize inputtemp;
@synthesize submit;
@synthesize outputtemp;
- (void)viewDidLoad
{
inputtemp.keyboardType = UIKeyboardTypeDecimalPad;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
…
- (IBAction)submit:(id)sender {
//defines input text
float temperature = [[inputtemp text] floatValue];
float sum = 0;
//selects formula based on convtype segment control
if (convtype.selectedSegmentIndex == 0) {
sum = (temperature * 9) / 5 + 32;
}
else if (convtype.selectedSegmentIndex == 1) {
sum = (temperature - 32) * 9 / 5;
}
//outputs to screen
[outputtemp setText:[NSString stringWithFormat:@"%3.2f", sum]];
}
@end
Is the problem with the setText? I’m not quite sure how to manipulate the ui label
needed to connect all the IBOutlets as HChouhan02 said