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

  • SEARCH
  • Home
  • 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 3793020
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:42:42+00:00 2026-05-19T12:42:42+00:00

I hope You are well, I’ve been working a few weeks on iphone and

  • 0

I hope You are well, I’ve been working a few weeks on iphone and at the moment I have a problem try to open a safari with a url, I have a json file that come a url which is dinamic.

here I leave the code.

- (void) loadFiles {

NSArray *_json = [[[self getDataFromJson] objectAtIndex:0] retain];
if ([_json count] > 0)
{
 for (int i = 0; i < [_json count]; i++)
 {
  NSDictionary *file = [_json objectAtIndex:i];

  UIImage *buttonImage = [UIImage imageNamed:@"btn.png"];
  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  [button setImage:buttonImage forState:UIControlStateNormal];

  [button addTarget:self action:@selector(openBrowser:) forControlEvents:UIControlEventTouchUpInside];

  //works but i have warnings
  button.tag = [file objectForKey:@"linkURL"] ;
  CGRect frame = CGRectZero;
  frame.size = buttonImage.size;
  button.frame = frame;

  NSString *name = [file objectForKey:@"name"];
  NSString *description = [file objectForKey:@"description"];


            //Create Box 

 }
}
}

- (void) openBrowser:(id)sender
{ 
 NSString *url = ((UIControl *) sender).tag;
 [[UIApplication sharedApplication]  openURL:[NSURL URLWithString:url] ];
}

I need to open from the UIButtom an URL without complaint .
Any suggestion or help thank you.
Cheers

  • 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-05-19T12:42:43+00:00Added an answer on May 19, 2026 at 12:42 pm

    Subclass UIButton and add a property to store the URL.

    // MyButton.h
    @interface MyButton : UIButton {
        NSString *urlString_;
    }
    
    @property (nonatomic, retain) NSString *urlString;
    
    @end
    
    
    
    // MyButton.m
    #import "MyButton.h"
    
    @implementation MyButton
    
    @synthesize urlString = urlString_;
    
    - (void)dealloc {
        [self setUrlString:nil];
        [super dealloc];
    }
    
    @end
    

    and then you continue with your code:

    #import "MyButton.h"
    .
    .
    .
    - (void) loadFiles {
    
        NSArray *_json = [[[self getDataFromJson] objectAtIndex:0] retain];
        if ([_json count] > 0)
        {
            for (int i = 0; i < [_json count]; i++)
            {
                NSDictionary *file = [_json objectAtIndex:i];
    
                UIImage *buttonImage = [UIImage imageNamed:@"btn.png"];
                MyButton *button = [MyButton buttonWithType:UIButtonTypeCustom];
                [button setImage:buttonImage forState:UIControlStateNormal];
    
                [button addTarget:self action:@selector(openBrowser:) forControlEvents:UIControlEventTouchUpInside];
    
                //works but i have warnings
                button.urlString = [file objectForKey:@"linkURL"] ;
                CGRect frame = CGRectZero;
                frame.size = buttonImage.size;
                button.frame = frame;
    
                NSString *name = [file objectForKey:@"name"];
                NSString *description = [file objectForKey:@"description"];
    
    
                //Create Box 
    
            }
        }
    }
    
    - (void) openBrowser:(id)sender {
        if ([sender isKindOfClass:[MyButton class]]) {
            [UIApplication sharedApplication] openURL:[NSURL URLWithString:[[(MyButton *)sender urlString]]];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really have tried my hardest on this little problem, its been 2 weeks
Well, I have a simple question, at least I hope its simple. I was
Hope the AWK gurus can provide a solution to my problem . I have
Well the problem I hope is simple, table represents data and by hovering the
Here's an interesting one... hope I can explain it well... I have a collection
Well I have a very rough version of gomoku working now. I'm using Jquery,
I have pydbgr working well now in Emacs 23.2 with virtualenv . But I
Hope all is well. I have a table with about 491,000 unique records in
I hope I can explain the question well enough. I have a table with
hope all of you doing well. I have small question in C#.Net. actually i

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.