所以我试图创建一个简单的温度转换的iPhone应用程序,当我运行代码输入我的号码并点击提交时,不显示任何内容。我似乎无法在这里找到问题是我的头文件
#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
基本上我有一个UISegmentedController来选择要做的转换(0是c到f,1是f到c)
我有一个文本字段inputtemp用于转换温度。提交是提交按钮,UIlabel outputtemp是我希望显示结果的地方。
不太确定这里出错的地方是.m文件中的其余代码
#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
setText有问题吗?我不太确定如何操纵ui标签
答案 0 :(得分:0)
需要连接所有IBOutlets,如HChouhan02所说