在我的应用程序中,我使用的是滚动视图(分页)。滚动视图 (UIImageView) 中的每个视图都包含一个图像,每个图像都有散布在图片上的标签(按钮)。所以这是我的代码:
for (int i = 0; i < self.pictures.count; i++)
{
//The first loop is to loop to every picture
int nbOfTags = classObject.tagsImages.count;
for (int j = 0; j < nbOfTags; j++)
{
//Second loop is to loop to each tag corresponding to the picture
ListTags *listTags = [[ListTags alloc]init];
NSMutableArray *tagInfo = [[NSMutableArray alloc]init];
listTags = [tagInfo objectAtIndex:j];
float tagX = [listTags.tag_x floatValue];
float tagY = [listTags.tag_y floatValue];
float x = 1024*i+ tagX;
float y = tagY;
CGRect rect = CGRectMake(x, tagY, 20, 20);
UIButton *button = [[UIButton alloc] initWithFrame:rect];
UIImage * buttonImage = [UIImage imageNamed:@"blueCircle.png"];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self.scrollView addSubview:button];
}
}
问题:当我运行代码时,我看不到图片上的按钮(标签)。如果我将“i”替换为“j”
浮动 x = 1024*i+ 标记X;
可以看到按钮,但它不是所需的坐标。那么为什么“我”不能工作?我做错了什么或错过了什么吗?