Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:38:27+00:00 2026-06-11T08:38:27+00:00

Im trying to add a UIAlertView to warn the user that the link will

  • 0

Im trying to add a UIAlertView to warn the user that the link will open in Safari. The user can then choose OK(open the url) or cancel which should just close the alert and return to the links.
I have three different UIButtons which has 3 different URLs.

Right now ive added a IBAction to all buttons and all buttons has Tags (which i think i can use somehow :D). I guess - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: delegate will be good to use to..

My question: how should the UIAlertView know what URL to open i user clicks ok?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:38:28+00:00Added an answer on June 11, 2026 at 8:38 am

    I suggest that you use a subclass of UIAlertView that is able to track some more properties along. I do this in all my projects and it is much simpler.

    • One solution to do this would be to subclass UIAlertView to MyAlertView and add a @property(nonatomic, retain) id userInfo; or @property(nonatomic, retain) NSURL* urlToOpen. Thus you can attach custom data to your UIAlertView and retrieve it in the delegate method to do whatever you need with it.
    • Another solution, and my preferred one actually, is to add Objective-C blocks support to UIAlertView, to be able to use UIAlertView using the blocks API instead of using a delegate. This is particularly useful if you use multiple UIAlertViews in the same class and with the same delegate, as using a single delegate to handle the different instances is a mess.

    I personally use this technique all the time, as it also makes my code more readable by having the code that executes when the button is tapped right next to the code that shows the alert, instead of having it at a complete different places when you use delegate methods.

    You can look at my OHAlertView subclass here on GitHub that implement this already. The usage is really simple and allow you to use blocks for each alert view instead of a common delegate, see below.


    Usage Example

    -(void)confirmOpenURL:(NSURL*)url
    {
      NSString* message = [NSString string WithFormat:@"Open %@ in Safari?",
                                                      url.absoluteString];
      [OHAlertView showAlertWithTitle:@"Open URL"
                              message:message
                         cancelButton:@"No"
                             okButton:@"Yes"
                       onButtonTapped:^(OHAlertView* alert, NSInteger buttonIndex)
      {
        if (buttonIndex != alert.cancelButtonIndex)
        {
           // If user tapped "Yes" and not "No"
           [[UIApplication sharedApplication] openURL:url];
        }
      }];
    }
    

    Then each button can have its own action:

    -(IBAction)button1Action
    {
      [self confirmOpenURL:[NSURL URLWithString:@"http://www.google.com"]];
    }
    -(IBAction)button2Action
    {
      [self confirmOpenURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];
    }
    

    Or you can have a common IBAction for all your buttons opening URLs:

    -(IBAction)commonButtonAction:(UIButton*)sender
    {
       NSUInteger tag = sender.tag;
       NSString* urls[] = { @"http://www.google.com", @"http://www.stackoverflow.com" };
       NSURL* buttonURL = [NSURL URLWithString: urls[tag] ]; // in practice you should check that tag is between 0 and the number of urls to be sure, that's just an example here
       [self confirmOpenURL:buttonURL];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying add some implicit rules in CMake that will generate direct dependencies (like
Im trying to add an constructor to my webservice, that looks like this: public
Am trying to add different numbers from different textbox, in a way that once
I am trying to add uitextfield to my alterview . When the user tries
I am trying add two columns in a text file that are seperated by
I'm trying add a directory of jar files (or barring that, each jar file
i'm new to django and im trying add a user using django admin page.
I'm trying add a tab to my web page that looks like this: Using
Trying to add an onclick handler to my tabs, and can't seem to get
trying to add an ExpiresDefault ExpiresByType to content on my website so that way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.