0

Following is my code. I can load all the image files from my NSMutableArray file but it didnt come out to my screen. I really dont know why. If anyone can help me with this would be really nice.

Thanks in advance.....

UIImageView *bannerImages;
    CGRect bannerFrame;

    for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++)
    {
        NSLog(@"photoCount: %d",photoCount);

        bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)];

        NSString *photoString = [NSString stringWithFormat:@"%@",[imagesFileList objectAtIndex:photoCount]];

        NSLog(@"photoString are: %@",photoString);

        bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

        bannerFrame = bannerImages.frame;
        bannerFrame.origin.y = self.view.bounds.size.height;
    }

    [UIView animateWithDuration:1.0
                          delay:1.0
                        options: UIViewAnimationTransitionCurlDown
                     animations:^{
                         bannerImages.frame = bannerFrame;
                     }
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];

    [self.view addSubview:bannerImages];
    [bannerImages release];

Here is my log file show:

2013-05-30 15:09:19.595 Yangon Guide Map[5035:15803] photoCount: 0
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv01.png
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 1
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv02.png
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 2
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv03.png
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoCount: 3
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoString are: edupro.png
2013-05-30 15:09:21.598 Yangon Guide Map[5035:15803] Done!
4

3 に答える 3

0

本当にやりたいことは何ですか?コードに多くのエラーがあるため...

1) UIImage -imageWithContentsOfFile: を作成しません。ファイルが見つかりません。次を使用します。

bannerImages.image = [UIImage imageNamed:photoString];

また

bannerImages.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[imageNamed:photoString stringByDeletingPathExtension] ofType:@"png"]];

2) 配列内の各画像に対して新しい UIImageView を作成しますが、最後の画像のみをルート ビューに追加します。for loop にそれぞれの UIImageView を追加します。

for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++)
{
     bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)];

     // Snip ...

[UIView animateWithDuration:1.0
                      delay:1.0
                    options: UIViewAnimationTransitionCurlDown
                 animations:^{
                     bannerImages.frame = bannerFrame;
                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

[self.view addSubview:bannerImages];
[bannerImages release];
}

3) スーパービューの境界を超えており、すべての UIImageView が同じフレームを持つため、bannerFrame の計算も間違っているようです。あなたのスーパービュー、 UIScrollView は何ですか? 何をしたいですか ?

于 2013-05-30T10:13:46.790 に答える
0

1..png画像が にあると仮定すると、App Bundle置き換えることができます

bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

bannerImages.image = [UIImage imageNamed:photoString]];

2. bannerFrame.origin.y = self.view.bounds.size.height;役に立たないようです。

于 2013-05-30T08:59:45.887 に答える