Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

phillipie99

macrumors newbie
Original poster
Jul 8, 2010
21
0
I just started iPhone programming and would like to know how to tell when some buttons have been pressed and then add to a variable that will display in three labels. I connected the buttons and labels to the interface using IB.

I had the variable part figured out
A = 0 (goes in label1)
B = 0 (goes in label2)
C = 0 (goes in label3)

When Button1 is pressed (A += 1)
When Button2 is pressed (B += 1)
(C += (A + B))

Use Button1 and Button2 and label1, label2, label3 in an example please.:)

Any help would be greatly appreciated and I hope this is enough information to get a good code example. :D
 
First, it would help if we knew what your programming experience is, as well as how much you know about Objective-C and Cocoa Touch.

Not too much, I started learing objective-c a few weeks ago and am able to perform arethmetic operations, connect objects with IB, and maybe a few other basic operations. As I said before I am pretty new to objective-c and programming in general so the simplist steps would be the best.
 
Have you ever connected a UI element event, via the Connections Inspector in IB, to an IBAction method that you've set up in a viewController?
 
Have you ever connected a UI element event, via the Connections Inspector in IB, to an IBAction method that you've set up in a viewController?

Nope never done that but I probably could easily with some guidance, and for some reason all the default IBOutlets were placed in the App delegate not the view controller (im making a tab bar app) so thats were I put mine, but I'm hoping that dosent matter.

They are also connected to the interface thorugh the connections list in the app delegate
 
Nope never done that but I probably could easily with some guidance...
I'm gonna suggest you step away from the real coding then and go learn the basics of Objective-C, Cocoa Touch, etc.. You could start by going through Apple's tutorial: Your First iPhone OS Application, which covers, among other things, connecting a UIButton event to an IBAction. Then maybe move on to other tutorials, books, iTunes U offerings, etc.
 
I'm gonna suggest you step away from the real coding then and go learn the basics of Objective-C, Cocoa Touch, etc.. You could start by going through Apple's tutorial: Your First iPhone OS Application, which covers, among other things, connecting a UIButton event to an IBAction. Then maybe move on to other tutorials, books, iTunes U offerings, etc.

That code listing has basicaly what I want to do, All I need to do is change the variables, the UIObjects and add the equasions in to a block. I've watched a few iTunes U videos about iAd and have iPhone development for dummies and Objective-c for dummies books that I use for reference. The link you posted pretty much solved my problem. Thanks I guess I didn't need a hard-coded exaple right from the forum.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.