PDA

View Full Version : Problems understanding how to link IBActions with storyboard




scrace89
Nov 23, 2011, 04:26 PM
I tried to follow a tutorial made before storyboard and I tried to link my buttons to IBActions as follows

control + click to the IBAction method.

Now when I click any of the buttons I get 0 or a huge int but never does what is should do and I don't understand why. I followed a basic tutorial on youtube. I'm a beginner programmer to objective-c and using Xcode 4.2 which is most of the problem but if anyone could help me out this is I would appreciate it.

http://i245.photobucket.com/albums/gg55/scrace89/ScreenShot2011-11-23at51443PM.png
http://i245.photobucket.com/albums/gg55/scrace89/ScreenShot2011-11-23at51551PM.png
http://i245.photobucket.com/albums/gg55/scrace89/ScreenShot2011-11-23at51532PM.png

Any good free guides or tutorials to help me understand IBActions and anything IU related using the interface?



jnoxx
Nov 24, 2011, 02:05 AM
I don't know how Storyboards work but.
IBActions, I can explain that to you though.

IBActions, simply means "Interface Builder Actions", this will provide a VOID method, because IBAction is simply a void method but with another name.
The tool where you define the interface is called Interface Builder, just got integrated in the IDE since Xcode 4.
So what it basicly does is, just tell the button to call an action you provide, and you can only hook it via IB (Interface Builder), if it's an IBAction, or if your button is a IBOutlet (Interface builder outlet), and you attach it via code.

None the less, you are adding an (id)sender to 1 method, but not to the rest, do you know what it does?

Also, I see you defining your integer above your interface, this is NOT recommanded
when you want to make ivars, avaible in your class.

@interface ViewController:UIViewController {
NSInteger anInt;
}

@property's go here

- methods go here


It's some basic Objective C things/Xcode things, you should maybe just read through some books.. I think it will help you more then just posting stuff on forums and waiting for people like me to answer.

xStep
Nov 24, 2011, 02:11 AM
One thing I notice is that your lines; number.text = [NSString stringWithFormat:@"%i"]; are missing the value you want to display.

It should be; number.text = [NSString stringWithFormat:@"%i", count];

scrace89
Nov 24, 2011, 06:21 AM
I don't know how Storyboards work but.
IBActions, I can explain that to you though.

IBActions, simply means "Interface Builder Actions", this will provide a VOID method, because IBAction is simply a void method but with another name.
The tool where you define the interface is called Interface Builder, just got integrated in the IDE since Xcode 4.
So what it basicly does is, just tell the button to call an action you provide, and you can only hook it via IB (Interface Builder), if it's an IBAction, or if your button is a IBOutlet (Interface builder outlet), and you attach it via code.

None the less, you are adding an (id)sender to 1 method, but not to the rest, do you know what it does?

Also, I see you defining your integer above your interface, this is NOT recommanded
when you want to make ivars, avaible in your class.

@interface ViewController:UIViewController {
NSInteger anInt;
}

@property's go here

- methods go here


It's some basic Objective C things/Xcode things, you should maybe just read through some books.. I think it will help you more then just posting stuff on forums and waiting for people like me to answer.

I have a good Xcode book, but not an xCode book. I've worked my way through half of Kochan's book and am bored with not getting to use the interface builders, I also have the big nerd ranch guide which I am going to crack open and start. I learn better by doing this that are too complex and asking question as well as reading. I just couldn't figure this out for some reason and it was so obvious once xStep said something.

I made the getter and setter methods for count by property and synthesizing it.

One thing I notice is that your lines; number.text = [NSString stringWithFormat:@"%i"]; are missing the value you want to display.

It should be; number.text = [NSString stringWithFormat:@"%i", count];

thank you so much, I'm an idiot.