Junior Bill gates
Junior Bill gates

Reputation: 1866

error: incompatible type for argument 1 of 'setText:

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

Upvotes: 1

Views: 1082

Answers (4)

PgmFreek
PgmFreek

Reputation: 6402

can you try

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

also change this line

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

Upvotes: 4

Chetan Bhalara
Chetan Bhalara

Reputation: 10344

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:

}

Upvotes: 2

visakh7
visakh7

Reputation: 26400

'k' is not a NSString. Try this

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

Upvotes: 1

Gypsa
Gypsa

Reputation: 11314

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

Upvotes: 0

Related Questions