开发者

error: incompatible type for argument 1 of 'setText:

开发者 https://www.devze.com 2023-03-05 00:12 出处:网络
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 he

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)app开发者_开发技巧licationDidFinishLaunching:(UIApplication *)application {    

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


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


@end


can you try

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

also change this line

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


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:

}


'k' is not a NSString. Try this

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


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

精彩评论

暂无评论...
验证码 换一张
取 消