iphone:如何在scrollview中为每个图像编码不同的标签

iphone:如何在scrollview中为每个图像编码不同的标签,iphone,nsarray,label,scrollview,Iphone,Nsarray,Label,Scrollview,我成功地为50幅图像创建了一个UIscrollview(水平),并且还创建了一个标签“1/50”页码,显示在图像顶部以及滚动视图(例如,用户滚动到下一幅图像,它将显示2/50、3/50等等)。我能够在图像底部显示一个标签作为描述。我的问题是如何创建或编码以显示每个图像的不同描述?我在想NSarray,但它显示了一些随机数。是否有一个样本,我可以看看我做错了什么。你可以看到我从那里迷路的描述部分。谢谢=) CGFloat xOffset=0; NSInteger页码=1; NSUI; 对于(i=1

我成功地为50幅图像创建了一个UIscrollview(水平),并且还创建了一个标签“1/50”页码,显示在图像顶部以及滚动视图(例如,用户滚动到下一幅图像,它将显示2/50、3/50等等)。我能够在图像底部显示一个标签作为描述。我的问题是如何创建或编码以显示每个图像的不同描述?我在想NSarray,但它显示了一些随机数。是否有一个样本,我可以看看我做错了什么。你可以看到我从那里迷路的描述部分。谢谢=)

CGFloat xOffset=0;
NSInteger页码=1;
NSUI;

对于(i=1;i您正在将descriptionLabel设置为
@“%d”
,这是一种十进制格式。什么是“description”?如果它是NSString,那么您应该使用
@“%@”

“我在考虑NSarray,但它会显示一些随机数。”--这是什么意思?抱歉,是%d构成了随机数,我刚刚用“%@”更新了我的帖子刚刚用正确的格式更新了我的帖子。正如你所看到的,数组中有5个不同的标签,它显示了所有图像中的所有标签。我想知道如何为第一个图像使用第一个标签,为第二个图像使用第二个标签…等等=)谢谢!嗯,我看不出来,因为你没有给我们看结果,也没有任何关于“描述”是什么的信息。“description”是一个字符串、一个C数组、一个NSArray还是什么?如果它是一个数组,您需要(duh!)为它建立索引--
[i]
objectAtIndex:i
。描述如解释图像显示内容的句子所示。我已经用数组进行了测试,但是它显示了数组中的所有标签,而不是第一个图像的第一个标签,依此类推。我仍然觉得我在这里遗漏了一些东西,但无法理解这是一个错误。它需要索引。你可以用objectAtIndex索引一个NSArray。你能给我一个样本吗
    CGFloat xOffset = 0;
        NSInteger pageNumber = 1;
            NSUInteger i;
        for (i = 1; i <= 5; i++)
        {
            NSString *imageName = [NSString stringWithFormat:@"creative%d.jpg", i];
            UIImage *image = [UIImage imageNamed:imageName];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

            [imageView setFrame:CGRectMake(xOffset, 0, 320, 288.5)];
            [ourScrollView addSubview:imageView];
            [imageView release];

            UILabel *pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, -10, 320, 40)];
            [pageNumberLabel setText:[NSString stringWithFormat:@"%d of 5", pageNumber]];
            [pageNumberLabel setTextAlignment:UITextAlignmentLeft];
            [pageNumberLabel setTextColor:[UIColor whiteColor]];
                    [pageNumberLabel setBackgroundColor:[UIColor clearColor]];
                    [pageNumberLabel setFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:18]];
            [ourScrollView addSubview:pageNumberLabel];
            [pageNumberLabel release];

  NSArray  *description = [NSArray arrayWithObjects:@"wow", @"bam", @"pow", @"zing", @"bling",nil];                 

                    UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, 250, 320, 40)];
                    [descriptionLabel setText:[NSString stringWithFormat:@"%@", description]];
                            [descriptionLabel setTextAlignment:UITextAlignmentLeft];
            [descriptionLabel setTextColor:[UIColor whiteColor]];
                    [descriptionLabel setBackgroundColor:[UIColor clearColor]];
            [ourScrollView addSubview:descriptionLabel];
            [descriptionLabel release];

            xOffset = xOffset + 320;
            pageNumber = pageNumber + 1;