条件をループする while ループがありますが、プロセスを複数回実行できません。
これが私の関連コードです:
NSInteger i = 0;
while(i <= building.departments.count)
{
NSLog(@"Number of building departments: %lu", (unsigned long)building.departments.count);
NSLog(@"i : %ld", (long)i);
UILabel *dtitleLB = [[UILabel alloc] initWithFrame:CGRectMake(5, y, 310, 20)];
dtitleLB.text = ((DBDepartment*)[building.departments objectAtIndex:i]).Name;
dtitleLB.textAlignment = UITextAlignmentLeft;
dtitleLB.backgroundColor = [UIColor clearColor];
dtitleLB.textColor = [UIColor lightGrayColor];
dtitleLB.font = [UIFont fontWithName:@"Helvetica" size:(16.0)];
[scrollView addSubview:dtitleLB];
y += 30;
UIButton* dphoneNB = [UIButton buttonWithType:UIButtonTypeCustom];
[dphoneNB setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[dphoneNB setTitleColor:[UIColor colorWithRed:0.3 green:0.3 blue:0.9 alpha:1.0] forState:UIControlStateNormal];
[dphoneNB addTarget:self action:@selector(numberPress:) forControlEvents:UIControlEventTouchUpInside];
[dphoneNB setTitle:((DBDepartment*)[building.departments objectAtIndex:i]).Phone forState:UIControlStateNormal]; i++;
dphoneNB.frame = CGRectMake(5, y, 315, 25);
[scrollView addSubview:dphoneNB];
y += 30;
UIButton* dwebsiteNB = [UIButton buttonWithType:UIButtonTypeCustom];
[dwebsiteNB setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[dwebsiteNB setTitleColor:[UIColor colorWithRed:0.3 green:0.3 blue:0.9 alpha:1.0] forState:UIControlStateNormal];
[dwebsiteNB addTarget:self action:@selector(linkPress:) forControlEvents:UIControlEventTouchUpInside];
[dwebsiteNB setTitle:((DBDepartment*)[self->building.departments objectAtIndex:i - 1]).Website forState:UIControlStateNormal]; i++;
dwebsiteNB.frame = CGRectMake(5, y, 315, 25);
[scrollView addSubview:dwebsiteNB];
y += 30;
i++;
}
最初の NSLog の出力は、ユーザーの選択に応じて 1 以上になります (決して 0 ではありません)。2 番目の NSLog の出力 = 0 であり、大きくなることはありません。
私のコードを調べて、明らかなエラーがあるかどうかを確認していただければ幸いです。
ありがとう!