程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-不能重載imageView

ios-不能重載imageView

編輯:編程綜合問答
不能重載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包含按鈕的標簽值。

最佳回答:


初始化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]];
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved