スクロールビューに追加する44個のボタンがあり、一連の配列を使用してそうしようとしていました。ファイル名の名前文字列、写真の Y サイズ (すべての x は同じ) などの配列があります。
メソッドを実行するviewDidLoadにあるコードは次のとおりです。
for (int i = 0; i < 44; i++) {
[self makeLabelsAndButtons:i];
}
メソッド makeLabelsAndButtons は次のとおりです。
-(void)makeLabelsAndButtons:(NSInteger *)indexPath{
NSString *nameString = [nameArray objectAtIndex:indexPath];
NSString *picString = [picArray objectAtIndex:indexPath];
NSInteger picNumb = [[numbers objectAtIndex:indexPath] integerValue];
NSInteger picXnum = [[picXCoords objectAtIndex:indexPath] integerValue];
Button = [UIButton buttonWithType:UIButtonTypeCustom];
[Button addTarget:self action:@selector(presPressed:)
forControlEvents:UIControlEventTouchUpInside];
Button.frame = CGRectMake(160.0, 240.0, 220.0, picNumb);
Button.center = CGPointMake(picXnum, 200.0);
[Button setBackgroundImage:[UIImage imageNamed:picString] forState: UIControlStateNormal];
[ScrollView addSubview:Button];
[ScrollView insertSubview:Button atIndex:1];
NSLog(@"name: %@, pic:%@, picY:%i", nameString, picString, picNumb);
}
ボタンは追加されていませんが、エラーは発生しません。何が間違っているのか本当にわかりません
助けてくれてありがとう!
編集:これは、スクロールビューを初期化する方法です
ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)];
ScrollView.showsVerticalScrollIndicator=YES;
ScrollView.scrollEnabled=YES;
ScrollView.bounces = YES;
ScrollView.userInteractionEnabled=YES;
[self.view addSubview:ScrollView];
[self.view insertSubview:ScrollView atIndex:1];
ScrollView.contentSize = CGSizeMake(20000,480);
NSLogs のシステムを介して、ボタンがビューに追加されていないと判断しましたが、その理由はわかりません。