0
votes

Unable to read Images from xcode project for example. drag and drop one image to xcode project, then read using following code.

__weak NSString *strTemp = [NSString stringWithFormat:@"%@/s_%@",[[NSBundle mainBundle] resourcePath],[[self.arr_gallery objectAtIndex:i]valueForKey:@"filename_larger"]];

            strTemp = [strTemp substringToIndex:[strTemp length]-3];

            strTemp = [NSString stringWithFormat:@"%@png",strTemp];

// NSString *strTemp = [[NSString alloc] initWithFormat:@"%@/[email protected]",[[NSBundle mainBundle] resourcePath]];

            UIImage *image;

            image = [[UIImage alloc] initWithContentsOfFile:strTemp];

            img.image = image;

            strTemp = nil;
1
What do you get if you NSLog("%@", strTemp)?Sekalf Nroc
Also, I'd change the variable name to something more revealing, such as imagePath.Sekalf Nroc
does it work on different devices?Ricardo Alves
Yes it;s work with 32 bit device.AtulParmar
Thanks Sekalf Nroc - I have checked it's getting nilAtulParmar

1 Answers

0
votes

Write following code.

 NSString *newStrTemp = [strTemp stringByReplacingOccurrencesOfString:@"jpg" withString:@"png"];    

Instead of this one.

strTemp = [strTemp substringToIndex:[strTemp length]-3];
strTemp = [NSString stringWithFormat:@"%@png",strTemp];