1

我添加图像而NSMutableArray不是转换它NSData并再次将该图像存储在其他图像中NSMutableArray。但是当我转换回给我错误的图像时

我的代码是

NSData *Puzzleimage;
PuzzleImg = [[NSMutableArray alloc] init];
TriangleImg = [[NSMutableArray alloc] init];

[PuzzleImg addObject:[UIImage imageNamed:@"Triangle_1.png"]];
    [PuzzleImg addObject:[UIImage imageNamed:@"Triangle_2.png"]];
    [PuzzleImg addObject:[UIImage imageNamed:@"Triangle_3.png"]];
    [PuzzleImg addObject:[UIImage imageNamed:@"Triangle_4.png"]];
    [PuzzleImg addObject:[UIImage imageNamed:@"Triangle_5.png"]];


    for (int l=0; l<[PuzzleImg count]; l++) {
        Puzzleimage = UIImagePNGRepresentation([PuzzleImg objectAtIndex:l]);
        [TriangleImg addObject:Puzzleimage];

在滚动视图中检索

 CGRect scrollViewFrame = CGRectMake(10, 60, 300, 350);
        PuzzleList = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
        [self.view addSubview:PuzzleList];

        int y1=10;
        int y2=10;
        if ([PuzzleImg count] >0)
        {
            for(int i=0;i<[PuzzleImg count];i++)
            {
                    UIImage *SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];
                    UIButton *btn =[[UIButton alloc]initWithFrame:CGRectMake(10, y1, 100, 100)];
                    [btn setBackgroundImage:SolImg forState:UIControlStateNormal];
                    btn.tag = i;
                    [btn addTarget:self action:@selector(SelectPuzzleButtonClick:) forControlEvents:UIControlEventTouchUpInside];

                    [PuzzleList addSubview:btn];
                    y1=y1+110;
         }
}

错误是 *错误显示在 Line ::UIImage SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];

-[UIImage 长度]:无法识别的选择器发送到实例 0xa1bc690 2013-04-10 10:41:47.292 CreativeLogic[2791:1a003] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[UIImage 长度]:无法识别的选择器sent to instance 0xa1bc690' * First throw call stack: (0x2612012 0x1422e7e 0x269d4bd 0x2601bbc 0x260194e 0x4cf1b2 0x38c1f3 0xc1d7 0xaac3 0xa532 0x44b817 0x44b882 0x44bb2a 0x462ef5 0x462fdb 0x463286 0x463381 0x463eab 0x4644a3 0x464098 0xe255 0x1436705 0x36d920 0x36d8b8 0x42e671 0x42ebcf 0x42dd38 0x39d33f 0x39d552 0x37b3aa 0x36ccf8 0x28fedf9 0x28fead0 0x2587bf5 0x2587962 0x25b8bb6 0x25b7f44 0x25b7e1b 0x28fd7e3 0x28fd668 0x36a65c 0x2022 0x1f55) libc++abi.dylib:终止调用抛出异常

4

2 回答 2

1

试着从这个改变...

UIImage *SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];

至 ...

UIImage *SolImg = [[UIImage alloc] initWithData:[TriangleImg objectAtIndex:i]];

我想这对你来说已经足够了

于 2013-04-20T04:32:31.210 回答
0

看到你添加UIImage为对象NSDataTriangleImg NSMutableArray不是PuzzleImg NSMutableArray对象,所以使用下面的行

UIImage *SolImg = [[UIImage alloc] initWithData:[TriangleImg objectAtIndex:i]];

而不是这条波纹线......

UIImage *SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];
于 2013-04-10T05:38:20.163 回答