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 6709689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:54:42+00:00 2026-05-26T07:54:42+00:00

Buttons are created dynamically and images are given to them through parsed urls, so

  • 0

Buttons are created dynamically and images are given to them through parsed urls, so i viewDidLoad i created them and released them in viewDidLoad only. So, when i click on Buttons i want to perform different tasks on click on different buttons. but i am not able to do it.
I tried to set Tag to them but again it is of no use as it is giving me EXC_BD_ACCESS…. any Help would be appreciated… 🙂
Code:-

@class AppDelegate_iPhone,Litofinter,ParsingViewController;

@interface FirstViewController : UIViewController<UIGestureRecognizerDelegate>{

    NSMutableArray *array;
    NSString *logoString;
    AppDelegate_iPhone *appDelegate;

    ParsingViewController *obj;

    UIScrollView *scrollView;

    NSMutableArray *idArray;
    NSMutableArray * currentPdfUrl;



}
@property (nonatomic,retain)UIScrollView *scrollView;

//-(void)onTapImage:(UITapGestureRecognizer *)recognizer;
-(void)onTapButton:(id)sender;

@end



#import "FirstViewController.h"
#import "AppDelegate_iPhone.h"
#import "Litofinter.h"
#import "ParsingViewController.h"
#import "MyGesture.h"

@implementation FirstViewController

@synthesize scrollView;

-(id)init{
    if(self == [super init]){
        obj = [[ParsingViewController alloc] init];
        array = [[NSArray alloc] initWithArray: obj.LogoMutableArray];
    }
    return self; 
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    int x=20,y=10;
    int a=50,b=105;


    appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,500, 460)];   
    scrollView.contentSize = CGSizeMake(320,800);
    scrollView.showsVerticalScrollIndicator = YES;

    for (Litofinter *lito in appDelegate.logoArray) {

        NSString * urlString = [lito.cLogo stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
        NSURL * imageURL = [NSURL URLWithString:urlString];

        NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
        UIImage * image = [UIImage imageWithData:imageData];
/*              
        UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
        [imgView setFrame:CGRectMake(x, y, 140, 90)];
        imgView.userInteractionEnabled = YES;
        imgView.multipleTouchEnabled = YES;
        imgView.backgroundColor = [UIColor blueColor];
    //  imgView.tag = lito.cId;
    //  NSLog(@"Tag Id = %@",imgView.tag);
        NSLog(@"Tag Id = %@",lito.cId);


        UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapImage:)];
        tgr.delegate = self;
        [imgView addGestureRecognizer:tgr];

        [scrollView addSubview:imgView];

        tgr.view.tag =(int)[NSString stringWithFormat:@"%@",lito.cId];
        NSLog(@"Tag Id = %@",tgr.view.tag);
    //  NSLog(@"Tag Id = %@",lito.cId);

*/      


        UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [imageButton setFrame:CGRectMake(x, y, 140, 90)];
        [imageButton setImage:image forState:UIControlStateNormal];
        [imageButton addTarget:self action:@selector(onTapButton:) forControlEvents:UIControlEventTouchUpInside];
        [imageButton setTag:lito.cId];
        [scrollView addSubview:imageButton];


        UILabel *cName = [[UILabel alloc]initWithFrame:CGRectMake(a, b, 130, 20)];
        cName.text = lito.cName;
        [scrollView addSubview:cName];

        //Do the rest of your operations here, don't forget to release the UIImageView
        x = x + 150;
        a = a + 140;

        if(x >300)
        {
            y = y +140;
            x = 20;
            b = b +150;
            a = 50;
        }

        //[tgr release];
    //  [imgView release];

    }
    [self.view addSubview:scrollView];


}

-(void)onTapButton:(id)sender
{
    NSLog(@"Tag Id = %@",self.view.tag);

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message from mAc" message:@"Tag Id" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
    [alert show];

}
  • 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-26T07:54:42+00:00Added an answer on May 26, 2026 at 7:54 am

    You could change the selector depending on the button when setting the target

    [imageButton addTarget:self action:@selector(onTapButton:) forControlEvents:UIControlEventTouchUpInside];
    

    If you want to do it with tags, it could also work, your bad access is coming from

    NSLog(@"Tag Id = %@",self.view.tag);
    

    Which is assuming that tag is an NSObject (responding to the description selector), when in fact, it is a numeric value. Change it to:

    NSLog(@"Tag Id = %i",self.view.tag);
    

    Also, you want to be careful when using

    NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
    

    as this is a synchronous API, it’s ok if it’s local files (although using [UIImage imageNamed:] is more economical as it caches the image data), it’s really bad if it’s network files (as it blocks the thread until the request ends, which could take ages).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many images which are created dynamically and I am showing them inside
I have several buttons on my app that are being created dynamically. They are
I've got some dynamic created buttons in my GridView (adding them OnDataBound), but when
I created a uiview(with two buttons) covers all the screen whenever i click on
I'm developing a little Android app with some square buttons created dynamically from Java
in my application i want to move plus image dynamically when iI click on
I am trying to upload various images into a dynamically created folder on my
I am just wondering here.. Aren't the PayPal buttons that are dynamically created, very
On my page, I have a dynamically generated list of radio buttons (created with
I have a GridView with dynamically created image buttons that should fire command events

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.