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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:39:14+00:00 2026-06-10T14:39:14+00:00

I am adding a button in UIScrollView in StoryBoard Below is the code i

  • 0

I am adding a button in UIScrollView in StoryBoard

Below is the code i am using.

-(void)addScrollView
{
    for(int i=0;i<[array count];i++)
    {
        UIScrollView *subScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 400, SUBSCROLLVIEW_WIDTH, SUBSCROLLVIEW_HEIGHT)];
        UITextView *txtVwDetail = [[UITextView alloc] initWithFrame:CGRectMake(342, 0, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT)];
        txtVwDetail.text = SAMPLE_STRING;
        [self addSubScrollView:subScrollView];
        [self.view addSubview:subScrollView];
        [self.view addSubview:txtVwDetail];
     }
}

-(void)addSubScrollView:(UIScrollView *)aSubScrollView
{
    for(int i=0;i<[array count];i++)
    {
        UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aButton.frame = CGRectMake(intBtnX, (aSubScrollView.frame.size.height - 80)/2, 50, 80);
        [aButton setImage:[UIImage imageNamed:[self.items objectAtIndex:i]] forState:UIControlStateNormal];
        **[aButton addTarget:self action:@selector(btnSubImageClicked) forControlEvents:UIControlEventTouchUpInside];**    
        aSubScrollView.contentSize = CGSizeMake(intScrollViewWidth, aSubScrollView.frame.size.height);
        [aSubScrollView addSubview:aButton];
    }
}

In addSubScrollView method I have added Button and its click event which is getting crashed.

-(void)btnSubImageClicked
{
    NSLog(@"btnSubImageClicked");
}

I am having scenario as

MyMainViewController is the sourceViewController for my created customSegue which is the UIStoryboardSegue class

MyMainViewController having a UIView as PlaceHolderView in which I am adding MydestinationViewContoller‘s View which is this Scrollview

-(void)perform
{
    BrowseScreenVC *srcObj = (BrowseScreenVC *)[self sourceViewController];
    UIViewController *dstObj = (UIViewController *)[self destinationViewController];

    for(UIView *vw in srcObj.viewPlaceHolder.subviews)
    {
        [vw removeFromSuperview];
    }

    NSLog(@"dest : %@",dstObj.view);
    NSLog(@"destobj  :%@",dstObj);
    srcObj.currentViewController = dstObj;
    [srcObj.viewPlaceHolder addSubview:[dstObj.view retain]];

}

UPDATE

With answer I also have to change the line
srcObj.currentViewController = dstObj;

to

srcObj.addChildViewController = dstObj;

to make it working

  • 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-10T14:39:16+00:00Added an answer on June 10, 2026 at 2:39 pm

    you have to add target as follow:

    [aButton addTarget:self action:@selector(btnSubImageClicked:) forControlEvents:UIControlEventTouchUpInside];
    

    @selector(), within these braces you have to provide the method that you want to perform. the “:” represents that the method has some argument. In this case the argument would be the button itself that is calling the method.

    You have to implement your method then its signature would look like this

    - (void)btnSubImageClicked:(id)sender{
    // sender would be the button that is calling the method. you can use this object according to your requirements if you want. 
    
       // your code 
    }
    

    if you want to call this method from somewhere else as well you can call it by passing sender argument nil. e.g [self btnSubImageClicked:nil];

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

Sidebar

Related Questions

I am using following code: slidingImageIconView=[[UIScrollView alloc]init]; [slidingImageIconScrollView setContentSize:CGSizeMake(110, 90)]; UIButton *iconImageSlide=[[UIButton alloc] init];
I am adding a button to a webform using hook_form_alter: $form['submit_ajaxSearch'] = array( '#type'
I have code that works great for adding a button to the toolbar: NSArray*
I am adding a button dynamically to HTML as shown below. When clicking that
I have some code below that creates a RelativeLayout and adds a button to
I'm having a problem after adding button on my star rating. Every time when
I am adding a button into UITableView by doing the following // Add checkOut
Is there a better way of adding a button at the bottom of a
I am customizing the ribbon toolbar and adding a button to it. Whenever I
I am customizing the ribbon toolbar and adding a button to it.Whenever I click

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.