Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Ryan Burgess

macrumors 6502
Original poster
Jan 26, 2013
320
48
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!!
 
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?
 
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?

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.
 
... get an error code.

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


How do I tell xcode to perform an action based on which button is tapped??
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.