How to make UIAlert appear after UIButton has been tapped?

Discussion in 'iOS Development' started by davidlansalot, Mar 25, 2009.

  1. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    Im having trouble with this part. Here is my current code...
    Code:
    - (IBAction)UIButton:(id)sender {
        UIButton *buttonClicked = (UIButton *)sender;
    	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Instructions" message:@"..." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
    	[alert show];
  2. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    on UIButton code, does it have @selector(UIButton

    Please Register or Log in to view images

    ?

    Code:
    - (IBAction)UIButton:(id)sender {
    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Instructions"
                                                        message:@"..."
                                                       delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"Ok"] autorelease];
        [alert show];
    }
    
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    what's not working? and did you set the selector of whatever UIControlEvent you want to that selector for your button?

    Code:
    UIButton* button; 
    // blah blah make button
    
    [button addTarget:self selector:@selector(UIButton:) forControlEvents:UIControlEventTouchUpInside];
    this is off the top of my head, so that may be slightly wrong.


    EDIT: if you're making the button in IB, make sure to connect the touch up inside event to that action.
  4. davidlansalot

    davidlansalot New Member

    Joined:
    Oct 29, 2007
    Messages:
    213
    Likes Received:
    0
    Device:
    2G iPod touch
    Im sure this is a complete noob question but I made the button in Interface Builder but it wont let me connect the button to touchUpInside. do u know why?
  5. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    touch up inside is a UIControlEvent that you can set an action selector for when your button sends that event message.

Share This Page