PDA

View Full Version : UIButton Programming




phillipie99
Jul 8, 2010, 02:48 PM
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



dejo
Jul 8, 2010, 02:53 PM
I connected the buttons and labels to the interface using IB.
Please elaborate. Did you connect the labels to IBOutlets and the buttons to IBActions?

phillipie99
Jul 8, 2010, 02:56 PM
Please elaborate. Did you connect the labels to IBOutlets and the buttons to IBActions?

I used IBOutlet should I use IBAction? If so how?

dejo
Jul 8, 2010, 03:07 PM
I used IBOutlet should I use IBAction? If so how?
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.

phillipie99
Jul 8, 2010, 03:14 PM
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.

dejo
Jul 8, 2010, 04:03 PM
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?

phillipie99
Jul 8, 2010, 04:11 PM
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

dejo
Jul 8, 2010, 04:21 PM
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 (http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhone101/index.html), which covers, among other things, connecting a UIButton event to an IBAction. Then maybe move on to other tutorials, books, iTunes U offerings, etc.

phillipie99
Jul 8, 2010, 07:28 PM
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 (http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhone101/index.html), 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.