I have an app that does a simple calculation from 2 text fields, the result is then displayed as label text. This is fine as long at each text field is populated, if no data is entered and the calculate button is pressed then the app closed. I assumed that blank would return a value of 0 and result would be displayed as 0. My code is as follows:
-(IBAction) tonerCalc: (id) sender{
NSString *tString;
int myInt = [textField1.text intValue];
int myInt1 = [textField2.text intValue];
int total = myInt/(myInt1/5);
tString = [[NSString alloc] initWithFormat:@"%i",total];
labelText.text = tString;
[tString release];
}
How can I stop the crash, I think it has something to do with the calculation. Any help is greatly appreciated.
You can put a check like
and if the condition is true then you can make your calculation do otherwise show alert.It will stop the crash.