2

私は20個のボタンを持っており、各ボタンをクリックすると、タグ値に関してその配列イメージがロードされます。私の問題は、最初のボタンの画像のみを表示することです。

    images=[[NSMutableArray alloc]init];


        [images insertObject:@"circle.png" atIndex:0];
        [images insertObject:@"cone.png" atIndex:1];
        [images insertObject:@"cube.png" atIndex:2];
        [images insertObject:@"cuboid.png" atIndex:3];
        [images insertObject:@"cylinder.png" atIndex:4];
        [images insertObject:@"ecplise.png" atIndex:5];
        [images insertObject:@"ellipsoid.png" atIndex:6];
        [images insertObject:@"frustrum of cone.png" atIndex:7];
        [images insertObject:@"kite.png" atIndex:8];
        [images insertObject:@"parallelepiped.png" atIndex:9];
        [images insertObject:@"parallelogram.png" atIndex:10];
        [images insertObject:@"polygon.png" atIndex:11];
        [images insertObject:@"rectangle.png" atIndex:12];
        [images insertObject:@"rectangula prizm.png" atIndex:13];
        [images insertObject:@"rhoumbus.png" atIndex:14];
        [images insertObject:@"sector.png" atIndex:15];
        [images insertObject:@"sphere.png" atIndex:16];
        [images insertObject:@"square.png" atIndex:17];
        [images insertObject:@"tapezoid.png" atIndex:18];
        [images insertObject:@"tourus.png" atIndex:19];
        [images insertObject:@"traingle.png" atIndex:20];


NSString * str=value2;


    NSLog(@"%@",str);

    //AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];




    NSInteger myInt = [str intValue];


    NSString *  imagename=[images objectAtIndex:myInt];

    NSLog(@"%@",imagename);


    self.imgview.userInteractionEnabled=YES;

    [imgview setImage:[UIImage imageNamed:imagename]];

    [imgview setNeedsDisplay];

    [imgview reloadInputViews];

str にはボタンのタグ値が含まれており、すべての値が適切に取得されますが、最初の画像のみが表示されます。

4

4 に答える 4

0

関連するボタンクリックで ImageArray から画像を取得する簡単なコードを提供します。

ボタンのメソッドがあるとします

-(void)buttonTapped:(UIButton *)sender
{
   images=[[NSMutableArray alloc]init];
   [images addObject:[UIImage imageNamed:@"myImage1.png"]];
   .
   .
   .

   UIImage *image = (UIImage *)[image objectAtIndex:sender.tag]; /// i Hope your each button has its own Tag.  

   /// here you get relavent image from button tapped by its tag;

  // put this image of you imageView.

   self.myImgView = [[UIImageView alloc] initWithFrame:CGRectMake("AS YOU NEED")];
   self.myImgView.image = image;
   [self.mainBG addSubview:self.myImgView];
}

ここで、ボタンにタグ o から 20 が付いていることを確認してください。

編集:

として使用します(コードをそのまま更新する必要がある例を示してください)

-(IBAction)buttonTapped:(id)sender 
{
      NSString *images[] = 
    {
       @"image0.png",
       @"image1.png",
       .
       .
       .
    };

  self.myImgView.image = [UIImage imageNamed: images[sender.tag]];
}
于 2013-07-06T10:52:38.720 に答える
0

please try the following.

1) try self.myImgView.image = [UIImage imageNamed:@"cube.png"] try using other images like @"rectangula prizm.png", @"tourus.png" ... See what happen if you set image directly. If the image is not displaying properly, then image is not inside bundle or image name is wrong.

于 2013-07-08T06:08:17.590 に答える