Help with linking AlertView to webpage??

Discussion in 'iOS Programming' started by Ryan Burgess, May 9, 2013.

  1. Ryan Burgess macrumors 6502

    Joined:
    Jan 26, 2013
    #1
    Hi, I've recently succeeded in completing my first simple iPhone app but I want to add one last thing before I submit to the app store. -

    The code I have is as follows;

    Code:
    (IBAction)buttonPressed {
        count++;
            
            scoreLabel.text = [NSString stringWithFormat:@"Score:\n%i", count];
        [buttonBeep play];
        
        if (count >= 100) {
            [timer invalidate];
            UIAlertView *displayed = [[UIAlertView alloc] initWithTitle:@"Upgrade Now" message:[NSString stringWithFormat:@"You rock! Upgrade now to remove ads and have no score limit!"] delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"App Store", nil];
            [displayed show];
        }
        
    }
    
    When the user clicks on "Not Now" I want the app to restart, using the code
    Code:
    [self setupGame]
    
    And when the user clicks "App Store" I want it to open the page for the full version app, in the app store. (www.apple.com for example) using the code:

    Code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @\"http://www.apple.com\"]];
    
    How would I implement this? How do I tell xcode to perform an action based on which button is tapped?? Thanks in advance!!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    I asked this in your other thread but never got an answer. So... I'll ask again:

    What resources have you been using to learn the fundamentals of Objective-C / iOS programming. Please try to be as specific as possible (that means for books: title, author, edition; for online tutorials, URLs, etc., etc., etc.)

    Also, what research have you already done to understand UIAlertViews and how to use them?
     
  3. Ryan Burgess thread starter macrumors 6502

    Joined:
    Jan 26, 2013
    #3
    I've been using the online tutorials at raywenderlich.com and I have tried many different combinations of code to get this working, but always get an error code.
     
  4. chown33, May 9, 2013
    Last edited: May 9, 2013

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    What is the error code? If it's a message, post the complete message text.

    I suggest reading this:
    http://www.mikeash.com/getting_answers.html


    A typical approach is to give each button its own action. It's the way to assign a specific action to a specific button. Why be general or vague, when you can be specific?

    If you absolutely must give the same action to multiple buttons, then a typical button-pressed action has a parameter, like this:
    Code:
    - (IBAction) myButtonClicked: (id)sender
    
    That 'sender' parameter is the UIButton * that is the sender of the message. You can choose different actions depending on the sender value itself, on the sender's tag property, on the sender's titleLabel property, etc.

    Or did you mean the button pressed in the UIAlertView? Kinda hard to tell what you mean when you have a buttonPressed method in the posted code.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Where did you learn about UIAlertViews?
     

Share This Page