Reputation: 630
i add image in NSMutableArray
than i convert it in NSData
and agaun i store that image in other NSMutableArray
. But when i convert back to image that give me Error
my Code is
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];
Retrive in Scroll View
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;
}
}
Error is *The error is display on Line ::UIImage SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];
-[UIImage length]: unrecognized selector sent to instance 0xa1bc690 2013-04-10 10:41:47.292 CreativeLogic[2791:1a003] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector 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: terminate called throwing an exception
Upvotes: 1
Views: 765
Reputation:
Try to change from this ...
UIImage *SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];
to ...
UIImage *SolImg = [[UIImage alloc] initWithData:[TriangleImg objectAtIndex:i]];
I think this is enough for you
Upvotes: 1
Reputation: 20541
See you add UIImage
as a NSData
in TriangleImg
NSMutableArray
object not in PuzzleImg
NSMutableArray
object so use bellow line
UIImage *SolImg = [[UIImage alloc] initWithData:[TriangleImg objectAtIndex:i]];
instead of this bellow line...
UIImage *SolImg = [[UIImage alloc] initWithData:[PuzzleImg objectAtIndex:i]];
Upvotes: 0