I have a simple calculator that works, but my problem is if the user doesn’t input any data into the fields then it still calculates. I thought I could do the following:
if (txtUserName.text == nil || txtUserName2.text == nil || txtUserName3.text == nil || txtUserName4.text == nil || txtUserName5.text == nil)
{
//error message
lblUserTypedName.text =@"Error - No Field Input";
}
else
{
lblUserTypedName.text = [[NSString alloc] initWithFormat: @"%2.1f%%", ultimate_risk];
}
But it’s not working at all. Any help letting me know what I am missing here would be greatly appreciated. I would like to use the || so even if they input all fields except one this will still catch it.
I would suggest using the length method of NSString to determine if there is any input. so you could use
This will work for both the text property being nil (which is the default value according to the documentation) and the text property being the empty string.
Also note that this still performs the calculation, it just does not display it. If you want to prevent the calculation you need to move the code to calculate
ultimate_riskinto the else block.