1

200を超える画像があり、ループを使用してNSArrayに追加したいのですが、どうすればこれを有効にできますか?

NSArray *imgArray = [NSArray arrayWithObjects:
                     [UIImage imageNamed:@"Ski_Seq0000.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0001.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0002.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0003.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0004.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0005.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0006.jpg"],
                     [UIImage imageNamed:@"Ski_Seq0007.jpg"],nil];

ループするには?

4

6 に答える 6

5
 NSMutableArray* imgArray = [[NSMutableArray alloc] arrayWithCapacity:200];

 for(int i = 0; i <= 200; i++)
 {
     UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"Ski_Seq%04d.jpg",i]];
     [imgArray addObject:image];
 } 

ただし、画像のサイズによっては、メモリ要件に注意する必要があります。

于 2012-09-20T06:44:55.370 に答える
3

このNSMutableArrayように使用する:

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (int x = 0; x < 200; x++) {
    [tempArray addObject:[NSString stringWithFormat:@"Ski_Seq%04d.jpg",x]];
}

NSArray *imgArray = [NSArray arrayWithArray:tempArray];
[tempArray release];//If you are not using ARC.
于 2012-09-20T06:43:08.130 に答える
2

これを行う:

NSMutableArray *ArrImgs = [[NSMutableArray alloc] init];
for(int i=0; i<=199;i++)
{
  NSString *strImg = [NSString stringithFormat:@"Ski_Seq%04d.jpg",i];
  [ArrImgs  addObject:[UIImage imageNamed:strImg]];

}
于 2012-09-20T06:43:19.520 に答える
2

画像を配列に保存する必要が本当にありますか?画像の名前だけを配列に格納するのはどうですか?

NSMutableArray* imagesName = [[NSMutableArray alloc] arrayWithCapacity:200];
for(int i = 0; i <= 200; i++){
    [imagesName addObject:[NSString stringWithFormat:@"Ski_Seq%04d",i]];
}

画像を取得します:

for(int i = 0; i <= [imagesName count]; i++){
   UIImage *image = [UIImage imageNamed:[imagesName objectAtIndex:i]];
}

本当に画像を配列に保存する必要がある場合は、ここで他の回答を参照できます:)

于 2012-09-20T07:00:41.503 に答える
1
 NSMutableArray *te=[[NSMutableArray alloc]init];

    for (int i=0; i<200; i++)
    {

        [te addObject: [UIImage imageNamed: [NSString stringWithFormat:@"Ski_Seq%04d.jpg",i]]];
    }

    NSArray *imgArray=[[NSArray alloc]initWithArray:[ te mutableCopy]];

    NSLog(@"the array::%@",imgArray);

これを試して...

于 2012-09-20T06:52:04.237 に答える
-1
 you try this code:

    @interface AnimationViewController : UIViewController
     {

         NSMutableArray *arrayImages;

          UIImageView *infoImage;

          NSTimer *timer;

            int i;

           NSTimeInterval timeInterval;

           NSDate *start;

       }



  -(void)animationStart
   {

   if (i==200) {

  [timer invalidate];
   timer=nil;        
   return;

   }

   NSLog(@"%d",i);

 infoImage.image=[UIImage imageNamed:[arrayImages objectAtIndex:i]];

  i++;
  }


      -(void)viewWillAppear:(BOOL)animated
       {
          [super viewWillAppear:animated];


        NSDate *start1 = [NSDate date];

       timeInterval = [start1 timeIntervalSince1970];

  timer=[NSTimer scheduledTimerWithTimeInterval:0.06 target:self selector:@selector(animationStart) userInfo:nil repeats:YES];

     NSLog(@"time---");

       }


    - (void)viewDidLoad
    {
     [super viewDidLoad];

    infoImage=[[UIImageView alloc]init];
    infoImage.frame=CGRectMake(0, 0, 320, 460);
    infoImage.backgroundColor=[UIColor clearColor];
    infoImage.image=[UIImage imageNamed:@"guideAmbi.png"];
    [self.view addSubview:infoImage];

    i=0;

   infoImage=[[UIImageView alloc]init];
   infoImage.frame=CGRectMake(0, 0, 320, 460);
   infoImage.backgroundColor=[UIColor clearColor];
   infoImage.image=[UIImage imageNamed:@"Info1.png"];
    [self.view addSubview:infoImage];

   arrayImages=[[NSMutableArray alloc]initWithCapacity:200];

    for (int is=1; is<=300; is++) 
    {
    NSString *str=[NSString stringWithFormat:@"Info%i.png",is];
    [arrayImages addObject:str];

     }  
于 2012-09-20T07:14:38.073 に答える