alllllllll 2013-07-08 09:09 采纳率: 0%
浏览 2173
已采纳

不能重载imageView

有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包含按钮的标签值。

  • 写回答

1条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-07-09 05:43
    关注

    初始化images数组的方法,你就不能写的简洁一些吗

    NSMutableArray *images=@{@"circle.png",@"cone.png",@"cube.png",@"cuboid.png",@"cylinder.png"}; ///后面的依次添加进去,这样看起来也简洁些
    NSString * str=value2;
    NSInteger myInt = [str intValue];
    ////判断别超出数组的下标
    if (myInt<images.count) {
          NSString *  imagename=[images objectAtIndex:myInt];
          self.imgview.userInteractionEnabled=YES;
         [self.imgview setImage:[UIImage imageNamed:imagename]];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘