adding numbers in uitextfield to update uilabel

I have code with several uitextfields that will be used to input numbers, and I want to add these numbers together to update a uilabel.

I can do all the updating and the labels and fields, but can't get the addition to work.

Just now I have:

label.text = (textfield1.text + textfield2.text);

I assume I need to convert these textfield inputs to an int, but not sure how to do that...


there is a couple of extra steps you have to do:

  1. convert the string value of your text filed into numerical value
  2. do the math there
  3. and convert it back.

For example (i use float in my case, you can change that to whatever type you want):

float textField1Value = [textfield1.text floarValue];

float textField2Value = [textfield2.text floarValue];

label.text = [NSString stringWithFormat:@"%f", textField1Value + textField2Value];

Hope that helps.

Need Your Help

SOAP error on Heart internet

php soap loopback

I have written following code on a server, which hosted on Heart internet UK.

How do I connect IntelliJ to GitHub using SSH

macos git github ssh intellij-idea

I have successfully configured my GitHub client to use SSH, and received the confirmatory email from GitHub that a new SSH key was added. I would like to setup IntelliJ to use SSH as well, so that ...