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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:10:04+00:00 2026-05-13T16:10:04+00:00

I have a problem with adding a set of UIButtons to a UIScrollView .

  • 0

I have a problem with adding a set of UIButtons to a UIScrollView. With the buttons added it seems that the scroll command is not being passed to the scroll view as the buttons cover the whole surface. I’ve read various posts on this but still can’t figure it out. I’m pretty new to iPhone programming so there’s probably something obvious I’ve missed. I’ve tried things like canCancelContentTouches and delaysContentTouches to TRUE and FALSE.

Here is the code I use to add the buttons to the UIScrollView. The UIScrollView was created in IB and is passed in to the function:

-(void)drawCharacters:(NSMutableArray *)chars:(UIScrollView *)target_view {
//NSLog(@"CLEARING PREVIOUS BUTTONS");
//clear previous buttons for parts/kanji
if(target_view == viewParts){
    for (UIButton *btn in parts_buttons) {
        [btn removeFromSuperview];
    }
    [parts_buttons removeAllObjects];
} else if(target_view == viewKanji){
    for (UIButton *btn in kanji_buttons) {
        [btn removeFromSuperview];
    }
    [kanji_buttons removeAllObjects];
}
//display options
int chars_per_line = 9; //change this to change the number of chars displayed on each line
if(target_view == viewKanji){
    chars_per_line = 8;
}
int char_gap = 0; //change this to change the margin between chars
int char_dimensions = (320/chars_per_line)-(char_gap*2);
//set starting x, y coords
int x = 0, y = 0;
//increment y coord
y += char_gap;
//NSLog(@"ABOUT TO DRAW FIRST BUTTON");
for(NSMutableArray *char_arr in chars){
    //increment x coord
    x += char_gap;
    //draw at x and y
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    myButton.frame = CGRectMake(x, y, char_dimensions, char_dimensions); // position in the parent view and set the size of the button
    [myButton setTitle:[char_arr objectAtIndex:0] forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0] forState:UIControlStateDisabled];
    myButton.titleLabel.font = [UIFont boldSystemFontOfSize:22];
    if(target_view == viewKanji){
        myButton.titleLabel.font = [UIFont boldSystemFontOfSize:30];
    }
    // add targets and actions
    if(target_view == viewParts){
        [myButton addTarget:self action:@selector(partSelected:) forControlEvents:UIControlEventTouchUpInside];
    } else if(target_view == viewKanji){
        [myButton addTarget:self action:@selector(kanjiSelected:) forControlEvents:UIControlEventTouchUpInside];
        [myButton setTag:(int)[char_arr objectAtIndex:1]];
    }

    //if the part isnt in the current list of kanji, disable and dim it
    if(target_view == viewParts){
        if([kanji count] > 0){
            [myButton setEnabled:NO];
        }
        bool do_break = NO;
        for(NSMutableArray *arr in kanji){
            //NSLog([NSString stringWithFormat:@"CHECKING PARTS AGAINST %d KANJI", [kanji count]]);
            for(NSString *str in [[arr objectAtIndex:2] componentsSeparatedByString:@" "]){
                if(([myButton.titleLabel.text isEqualToString:str])){
                    //NSLog(@"--------------MATCH!!!-----------------");
                    [myButton setEnabled:YES];
                    for(NSString *str1 in parts_selected){
                        if(([myButton.titleLabel.text isEqualToString:str1])){
                            [myButton setEnabled:NO];
                            break;
                        }
                    }
                    do_break = YES;
                    break;
                }
                if(do_break) break;
            }
            if(do_break) break;
        }
    }
    // add to a view
    [target_view addSubview:myButton];
    //update coords of next button
    x += char_dimensions+ char_gap;
    if (x > (320-char_dimensions)) {
        x = 0;
        y += char_dimensions + (char_gap*2);
    }
    //add button to global array to be removed from view next update
    if(target_view == viewParts){
        [parts_buttons addObject:myButton];
    } else if(target_view == viewKanji){
        [kanji_buttons addObject:myButton];
    }
}
//NSLog(@"FINISHED DRAWING ALL BUTTONS");

}

Any help on this would be greatly appreciated. I just need to fix this to finish my app.

  • 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-13T16:10:04+00:00Added an answer on May 13, 2026 at 4:10 pm

    You cannot expect the scrollview to receive events if the buttons cover the whole surface.(They are going to be first in the responder chain). The quick fix would be to make the buttons slightly smaller than the scrollview.

    On first read of this problem I was thinking that you wanted to add buttons to the scrollview’s superview — but then I realized you actually want the buttons in the scrollview.

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

Sidebar

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.