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

时间:2011-05-10 09:42:26

标签: iphone objective-c uilabel

嗨我正在为目标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 个答案:

答案 0 :(得分:4)

你可以尝试

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

也改变了这一行

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

答案 1 :(得分:2)

试试这个,

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

}

答案 2 :(得分:1)

'k'不是NSString。试试这个

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

答案 3 :(得分:0)

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