I'm fairly new to iOS programming, but have a basic understanding of it. I have been doing fine programming with Xcode 3, but now that Xcode 4.2 is out, things are much more difficult (with the changes in templates and all).
Now for my problem:
I am using single page application
In my ViewController.h I have this:
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *Num1;
@property (weak, nonatomic) IBOutlet UITextField *Num2;
@property (weak, nonatomic) IBOutlet UILabel *answer;
- (IBAction)addNums:(id)sender;
In my ViewController.m I have this:
- (IBAction)addNums:(id)sender
{
int x = ([Num1.text floatValue]);
int y = ([Num2.text floatValue]);
int ans = x + y;
answer.text = @"%i", ans;
}
I have connected everything to files owner properly, but I keep getting this message saying, "Expression Result Unused."
Again, I'm very sorry for my idiotic question, its just that i can't find any tutorials for Xcode 4.2 online, and I can't find any books on it.
Instead of your:
answer.text = @"%i", ans;
Do:
float x = ([Num1.text floatValue]);
float y = ([Num2.text floatValue]);
[answer setText:[NSString stringWithFormat:@"%i", x + y]];
First, it would help if you didn't change your numbers to floating point values and assign the floating point type to an integer variable. Also concerning that statement, the () are unneeded because you are already using brackets, which have a higher order of operations than the assignment (=) operator, instead do:
int x = [num1.text integerValue];
and repeat for y.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With