views:

560

answers:

1

I may be missing something silly. But I've been staring at it for a day now and re-working it and what not. I still get the same "Expected expression before '{' token" error.

Before I got this error I was having trouble getting my button to do what I was asking it to do, which was simply add the two numbers and display the answer, basically. Here's the bit of code giving me the problem:

-(IBAction)click:(id)sender {   
    int sum = [myInt1.text intValue] + [myInt2.text intValue];
    label.text = {NSString stringWithFormat:@"%@ the answer is %d",
        name.text, sum];
}
+14  A: 

Replace:

label.text = {NSString ...

with:

label.text = [NSString ...

(the parenthesis before NSString).

Eimantas
wow. it really was something that silly. thank you very much. the button still isnt working, but at least i got the error to go away :)
jxd215
Everyone makes these mistakes, and sometimes they can hide out for hours! In fact, i didn't really see that error...
RCIX
you're welcome. These are sort of typos that make you really bang your head against a keyboard (or wall) once you find what you typed wrong ,)
Eimantas
It happens to me all the time, I miss the small stuff. I'm kinda new to objective-c and I'm still working out the kinks. Could I ask if someone could kindly take a look at my code and maybe give me an idea of what Im missing to make the button work?
jxd215
You should accept the answer if it fixed your problem.
mos