错误:'setText的参数1的不兼容类型:

时间:2022-12-11 20:24:40

hi i am writing a temperature converter program in objective c for i phone my code is given below i am getting an error ""error: incompatible type for argument 1 of 'setText:"" please somebody help me to solve my problem

嗨我正在写一个目标c的温度转换器程序,我的手机我的代码在下面给出我收到错误“”错误:'setText:'参数1的不兼容类型“请有人帮我解决我的问题

1. interface section

#import <UIKit/UIKit.h>

@interface farh_celcius_conv_AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UILabel *display;
    IBOutlet UITextField *farhenite;
    IBOutlet UIButton *convert;
    float n ;
    float k;
}

-(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

2. implementation section
#import "farh_celcius_conv_AppDelegate.h"

@implementation farh_celcius_conv_AppDelegate

@synthesize window,display,farhenite;

-(IBAction) convert {

    NSString *str = [NSString txt];

    float n = [str floatValue];

    k = (n - 32)*(5/9);

        [display setText: k]; 

   // error:incompatible type for argument 1 of 'setText:

}

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

4 个解决方案

#1


1  

'k' is not a NSString. Try this

'k'不是NSString。尝试这个

[display setText:[NSString stringWithFormat:@"%f",k]];

#2


4  

can you try

你能试一下吗

 display.text = [NSString stringWithFormat:@"%f",k];

also change this line

也改变了这一行

NSString *str = youStr  //rather than [NSString txt].

#3


2  

Try this,

Because, k is not a NSString.

因为,k不是NSString。

-(IBAction) convert {

    NSString *str = [NSString stringWithFormat:@"%@", farhenite.text];

    float n = [str floatValue];

    k = (n - 32)*(5/9);

        //[display setText: k]; 
   display.text = [NSString stringWithFormat:@"%f", k];

   // error:incompatible type for argument 1 of 'setText:

}

#4


0  

[self.display setText:[NSString stringWithFormat:@"%f",k]];

#1


1  

'k' is not a NSString. Try this

'k'不是NSString。尝试这个

[display setText:[NSString stringWithFormat:@"%f",k]];

#2


4  

can you try

你能试一下吗

 display.text = [NSString stringWithFormat:@"%f",k];

also change this line

也改变了这一行

NSString *str = youStr  //rather than [NSString txt].

#3


2  

Try this,

Because, k is not a NSString.

因为,k不是NSString。

-(IBAction) convert {

    NSString *str = [NSString stringWithFormat:@"%@", farhenite.text];

    float n = [str floatValue];

    k = (n - 32)*(5/9);

        //[display setText: k]; 
   display.text = [NSString stringWithFormat:@"%f", k];

   // error:incompatible type for argument 1 of 'setText:

}

#4


0  

[self.display setText:[NSString stringWithFormat:@"%f",k]];