Instead of denying the use of a math function, I assigned an NSMutableString to my UITextField, after which I inserted the β-β sign using insertString: atIndex: after that I reassigned the modified line to my UITextField. To switch between positive and negative, I created an if function, so if the float value of my text field is greater than or equal to 0, then a β-β is added, but if the float value of my text field is less than zero, it is βdeleted using deleteCharactersInRange. Here is my code in its current form:
- (IBAction)positivity{
NSMutableString *a = [NSMutableString stringWithString:aVal.text];
if([aVal.text floatValue]>=0){
[a insertString: @"-" atIndex: 0];
aVal.text = a;
}
else if([aVal.text floatValue]<0){
NSRange range = {0,1};
[a deleteCharactersInRange:range];
aVal.text = a;
}
}
aVal is the name of the UITextField that I am changing.
source
share