温度转换器不输出 [英] temperature converter not giving output
本文介绍了温度转换器不输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了用于iPhone的温度转换代码,但是它无法正常工作,也没有给出任何错误,请帮忙
i have written a code for temperature conversion for iphone but it is not working and neither giving any error please help
界面部分
#import <UIKit/UIKit.h>
float n ;
float k;
@interface farh_celcius_conv_AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UILabel *display;
IBOutlet UITextField *farhenite;
IBOutlet UIButton *convert;
}
-(IBAction) convert;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UILabel *display;
@property (nonatomic, retain) IBOutlet UITextField *farhenite;
@property (nonatomic, retain) IBOutlet UIButton *convert;
@end
实施部分
#import "farh_celcius_conv_AppDelegate.h"
@implementation farh_celcius_conv_AppDelegate
@synthesize window,display,farhenite;
-(IBAction) convert {
NSString *str = [NSString text];
float n = [str floatValue];
k = (n - 32)*(5/9);
[display setText:[NSString stringWithFormat:@"%f",k]];
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
推荐答案
如果要转换在textField中输入的值,则方法应如下所示
If you want to convert the value entered in textField you the method should be like this
-(IBAction) convert {
NSString *str = yourTextField.text; // In your case farhenite i guess
float n = [str floatValue];
k = (n - 32)*(5/9);
[display setText:[NSString stringWithFormat:@"%f",k]];
}
这篇关于温度转换器不输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文