Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create simple addition in Objective-C?
    text
    copied!<p>I have a simple iPhone project open in Xcode. In the storyboard file i have a view controller with : 2 text fields 1 label 1 round rect button</p> <p>What I am trying to do is the following: Have the user enter any number in field A, then the same on field B. Then once the "Submit" button has been pressed, I would like the app to add the two values. </p> <p>So far this is the code that I have but I am currently stuck as I am getting an error on build.</p> <p>My Header file: </p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ADDViewController : UIViewController @property (copy,nonatomic) NSString *valueA; @property (copy,nonatomic) NSString *valueB; @end </code></pre> <p>My Implementation File:</p> <pre><code>#import "ADDViewController.h" @interface ADDViewController () - (IBAction)submitButton:(id)sender; @property (weak, nonatomic) IBOutlet UITextField *numberA; @property (weak, nonatomic) IBOutlet UITextField *numberB; @property (weak, nonatomic) IBOutlet UILabel *answerLabel; @end @implementation ADDViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)submitButton:(id)sender { self.valueA = self.numberA.text; self.valueB = self.numberB.text; // THE FOLLOWING IS WHERE I AM CURRENTLY GETTING AN ERROR WITH XCODE: // XCODE SAYS : INVALID OPERANDS TO BINARY EXPRESSION ('NSSTRING *' AND 'NSSTRING *') NSString * total = self.valueA + self.valueB; } @end </code></pre> <p>And this is a screen shot of my story board file:</p> <p><a href="http://i43.tinypic.com/352q98i.jpg" rel="nofollow">http://i43.tinypic.com/352q98i.jpg</a></p> <p>Thank you in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload