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

发布于 2024-11-05 19:29:39 字数 1281 浏览 1 评论 0原文

你好,我正在为我的手机在 Objective 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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十二 2024-11-12 19:29:39

你可以尝试

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

也改变这条线吗

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

can you try

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

also change this line

NSString *str = youStr  //rather than [NSString txt].
我只土不豪 2024-11-12 19:29:39

试试这个,

因为 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:

}

Try this,

Because, k is not a 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:

}
落在眉间の轻吻 2024-11-12 19:29:39

'k' 不是 NSString。试试这个

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

'k' is not a NSString. Try this

[display setText:[NSString stringWithFormat:@"%f",k]];
盗琴音 2024-11-12 19:29:39
[self.display setText:[NSString stringWithFormat:@"%f",k]];
[self.display setText:[NSString stringWithFormat:@"%f",k]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文