UIButton Programming

Discussion in 'iOS Programming' started by phillipie99, Jul 8, 2010.

  1. phillipie99
    Expand Collapse
    macrumors newbie

    Joined:
    Jul 8, 2010
    #1
    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
     
  2. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Please elaborate. Did you connect the labels to IBOutlets and the buttons to IBActions?
     
  3. phillipie99
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Jul 8, 2010
    #3
    I used IBOutlet should I use IBAction? If so how?
     
  4. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. phillipie99
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Jul 8, 2010
    #5
    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.
     
  6. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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?
     
  7. phillipie99
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Jul 8, 2010
    #7
    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
     
  8. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    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.
     
  9. phillipie99
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Jul 8, 2010
    #9
    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.
     

Share This Page