Incompatible pointer to integer sending 'UITextField*

120 Views Asked by At

I have an issue with UITextField

I want user enter the date to run notification and I use this in .m

  [dateComponent setWeekday:1]; // For sunday
  [dateComponent setHour:timeHClass];
  [dateComponent setMinute:timeMClass];

and this in .h

  @property (retain, nonatomic) IBOutlet UITextField *timeHClass;
  @property (retain, nonatomic) IBOutlet UITextField *timeMClass;

but it shows me this warning:

incompatible pointer to integer sending 'UiTextField*__strong' to parameter of type 'NSInteger' (aka 'long')

4

There are 4 best solutions below

0
On BEST ANSWER

You should be doing:

[dateComponent setHour:[timeHClass.text integerValue]];
[dateComponent setMinute:[timeMClass.text integerValue]];

You want to get the text typed in the field and use it with your date component.

Explanation: timeHClass object is an UITextField so you want to access the text property of it, which is an NSString object, and convert it to an NSInteger value. You should also make sure that your text field is numeric.

0
On

You are setting the UITextField properties of your class as the hour and minute components. These fields call for integers, just like you did with [dateComponent setWeekday:1];.

1
On

You are trying to send a pointer to an UITextField * object as a parameter which should be NSInteger instead. Try:

[dateComponent setHour:[timeHClass.text integerValue]];

But be really careful with this type of conversion, user might type in something you don't want. You'll have to check the input text beforehand to avoid unpredictable behaviour.

0
On

You have to take the content of your text field, not your textfield itself:

[dateComponent setWeekday:1]; // For sunday
[dateComponent setHour:[timeHClass.text integerValue]];
[dateComponent setMinute:[timeMClass.text integerValue];