I have a problem adding a set UIButtonsto UIScrollView. With the buttons added, it seems that the scroll command is not passed to the scroll, since the buttons cover the entire surface. I read various posts about this, but still can not understand. I'm new to iPhone programming, so maybe something obvious that I missed. I tried things like canCancelContentTouchesand delaysContentTouchesin TRUE and FALSE.
Here is the code that I use to add buttons to UIScrollView. UIScrollViewwas created in IB and passed to the function:
-(void)drawCharacters:(NSMutableArray *)chars:(UIScrollView *)target_view {
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];
}
int chars_per_line = 9;
if(target_view == viewKanji){
chars_per_line = 8;
}
int char_gap = 0;
int char_dimensions = (320/chars_per_line)-(char_gap*2);
int x = 0, y = 0;
y += char_gap;
for(NSMutableArray *char_arr in chars){
x += char_gap;
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(x, y, char_dimensions, char_dimensions);
[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];
}
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(target_view == viewParts){
if([kanji count] > 0){
[myButton setEnabled:NO];
}
bool do_break = NO;
for(NSMutableArray *arr in kanji){
for(NSString *str in [[arr objectAtIndex:2] componentsSeparatedByString:@" "]){
if(([myButton.titleLabel.text isEqualToString:str])){
[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;
}
}
[target_view addSubview:myButton];
x += char_dimensions+ char_gap;
if (x > (320-char_dimensions)) {
x = 0;
y += char_dimensions + (char_gap*2);
}
if(target_view == viewParts){
[parts_buttons addObject:myButton];
} else if(target_view == viewKanji){
[kanji_buttons addObject:myButton];
}
}
}
Any help on this would be greatly appreciated. I just need to fix this in order to complete my application.