UIPushButton help?

Discussion in 'iOS Development' started by Tyr0, Jul 29, 2008.

  1. Tyr0

    Tyr0 New Member

    Joined:
    Dec 17, 2007
    Messages:
    533
    Likes Received:
    6
    Device:
    iPhone 3GS (White)
    okay, i have seriously been searching for an answer to this ALL DAY. how do i get my push button to do what i tell it to. Plz help, as im just learning.
    thx -tyr0
  2. palad1

    palad1 New Member

    Joined:
    Apr 8, 2008
    Messages:
    3
    Likes Received:
    0
    easy peasy

    Please Register or Log in to view images



    Code:
    /*field defs*/
    UIPushButton * pButton;
    /*snip*/
    /* init method */
    pButton=[[[UIPushButton alloc] autorelease] /*intitWithFoo...*/];
    /*snip*/
    [pButton addTarget:self action:@selector(pButtonAction:) forEvents:(255)];
    
    /*snip*/
    
    - (void)pButtonAction:(UIPushButton *)button {
      if(button==pButton){
        /* Go crazy */
      }
    }
    
    
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I haven't used on on 2.0 yet, but here's the code for 1.x.

    Code:
    	UIPushButton *yourButton = [[UIPushButton alloc] init];
    	[yourButton setOrigin:CGPointMake(0,0)]; //OR wherever.
    	[yourButton setImage:[UIImage imageNamed:@"aPng.png"] forState:0];
    	[yourButton setImage:[UIImage imageNamed:@"anotherPng.png"] forState:1];
    	[yourButton addTarget:self action:@selector(yourButtonPressed) forEvents:kUIControlEventMouseUpInside]; //Specifically, you're asking for this.
    	[yourButton setEnabled:TRUE];
  4. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    ^^^^^^^^^^^^^^^^^NICE example skylar

    Please Register or Log in to view images

    ^^^^^^^^^^^^^^^^^^
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Yeah, but we can't talk about UIButton, Gojohnnyboi. You know, NDA and all. Please remove the code from your post.
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    ahhh fcking nda. fixed it

    Please Register or Log in to view images

Share This Page