I am new to objective c,so plz me help with this…
i have used three textfields in the interface builder
textfield1 inputs the first number
textfield2 inputs the second number
and i have created a button called sum which will calculate the sum
and textfield(ans) will display the result
.h file code
{
IBOutlet UITextfield txtfield1;
IBOutlet UITextfield txtfield2;
IBOutlet UITextfield ans;
}
-(IBAction)add;
.m file code
-(IBAction)add
{
int result=[txtfield1.text intValue]+[txtfield2.text intValue];
ans.text=[NSString StringWithFormat:@"%d",result];
}
The program runs fine,but i want only integer values to be entered in the textfield,if i enter alphabets and click on the sum button i get 0 as the ans,what can i do so that user gets an error when he inputs alphabets..thanks..
-textField:shouldChangeCharactersInRange:replacementString:is a delegate method that let’s you allow only certain characters to be in the text field.This returns YES and therefore allows only characters that are not in the decimalDigitCharacterSet character set.