iOS [__NSArrayM insertObject:atIndex:]: object cannot be nil - So Annoying - ios
This is driving me crazy!
I'm seeing :
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
* First throw call stack:
(0x28f9012 0x271ee7e 0x28acb6a 0x28aca20 0x5866c 0x5eeee 0x154f103 0x154f42b 0x155cf80 0x1564fad 0x156589b 0x1565e93 0x1565a88 0x8628 0x2732705 0x146f2c0 0x16aba64 0x2732705 0x146f2c0 0x146f258 0x1530021 0x153057f 0x152f6e8 0x149ecef 0x149ef02 0x147cd4a 0x146e698 0x2d76df9 0x2d76ad0 0x286ebf5 0x286e962 0x289fbb6 0x289ef44 0x289ee1b 0x2d757e3 0x2d75668 0x146bffc 0x3210 0x3175)
libc++abi.dylib: terminate called throwing an exception
First break point is catching at :
NSMutableArray *imgArray = [NSMutableArray array];
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
[imgArray addObject:img1]; //Breaking Here....
Not sure how this has suddenly started becoming an issue, i've restored back to earlier builds, tried another workstation however still seeing this error in the below code :
Any ideas? (had to trim the file hence the sudden ending)
#implementation IMReviewViewController {
UIScrollView *scrollView;
//UIPageControl *pageControl;
BOOL continueButtonDisabled;
NSUInteger downloadedImageCount;
}
#synthesize frameImage;
#synthesize removeButton;
#synthesize caption;
#synthesize delegate;
#synthesize photo = _photo;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)dealloc
{
NSLog(#"dealloc - IMReviewViewController");
}
- (void)buttonPressed:(id)sender
{
// if (self.delegate && [self.delegate respondsToSelector:#selector(removePhoto:)]) {
// [self.delegate removePhoto:removePhoto:self.photo];
// }
for (UIView *view in scrollView.subviews) {
[view removeFromSuperview];
}
[self.navigationController popViewControllerAnimated:YES];
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShadow(context, CGSizeMake(3.0f, 3.0f), 2.0f);
if (self.frameImage) {
[self.frameImage drawInRect:rect];
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)setReviewImages
{
continueButtonDisabled = YES;
downloadedImageCount = 0;
NSArray *reviewViews = scrollView.subviews;
for (IMReviewView *reviewView in reviewViews) {
[reviewView removeFromSuperview];
}
NSUInteger photoCount = [[IMLocalUser localUser] cachedPhotoCount];
if ( nPageNum == 0 ){
for (NSUInteger i = 0; i < photoCount; i++) {
CGRect frame;
frame.origin.x = scrollView.frame.size.width * i;
frame.origin.y = 65;
frame.size = CGSizeMake(scrollView.frame.size.width, 327.0f);
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:i];
[scrollView addSubview:subview];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * i, scrollView.frame.size.height);
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
[self.view addSubview:headingLabel];
headingLabel.text = #"Time To Preview!";
headingLabel.textColor = [UIColor blackColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blackColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
}
// pageControl.numberOfPages = photoCoun
}else if( nPageNum == 1 ){
int nVWidth, nVHeight;
nVWidth = self.view.frame.size.width;
nVHeight = (self.view.frame.size.height - 310) / 2;
CGRect frame;
frame.origin.x = 27.0f;
frame.origin.y = 65;
frame.size = CGSizeMake(269.5f, 253.5f);
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
NSURL *imageURL = [[NSBundle mainBundle] URLForResource:#"FramedBack" withExtension:#"png"];
frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
//Header Text above print
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
[self.view addSubview:headingLabel];
headingLabel.text = #"Time To Preview!";
headingLabel.textColor = [UIColor blackColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blackColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
//----------------
UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
CGSize divSize = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT);
UIImage *image = [[UIImage alloc] init];
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
//image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];
image = img1;
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(300, 300, divSize.width-600, divSize.height-600)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
[viewImage setFrame:frame];
[scrollView addSubview:viewImage];
NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:#"RemoveIcon#2x" withExtension:#"png"];
UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
[self.removeButton setImage:buttonImage forState:UIControlStateNormal];
[self.removeButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.removeButton];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
}else if( nPageNum == 2 ){
int nVWidth, nVHeight;
nVWidth = self.view.frame.size.width;
nVHeight = (self.view.frame.size.height - 330) / 2;
CGRect frame;
frame.origin.x = 27.0f;
frame.origin.y = 65;
frame.size = CGSizeMake(269.5f, 253.5f);
NSMutableArray *imgArray = [NSMutableArray array];
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
[imgArray addObject:img1];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
UIImage *img2 = [[UIImage alloc] init];
img2 = subview.photo.image;
[imgArray addObject:img2];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
UIImage *img3 = [[UIImage alloc] init];
img3 = subview.photo.image;
[imgArray addObject:img3];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
UIImage *img4 = [[UIImage alloc] init];
img4 = subview.photo.image;
[imgArray addObject:img4];
NSURL *imageURL = [[NSBundle mainBundle] URLForResource:#"FramedBack" withExtension:#"png"];
frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
//Header Text above print
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
[self.view addSubview:headingLabel];
headingLabel.text = #"Time To Preview!";
headingLabel.textColor = [UIColor blackColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blackColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
//Footer Text under print
UILabel *footer = [[UILabel alloc] initWithFrame:CGRectMake(50, 330, 226, 50)];
[self.view addSubview:footer];
footer.text = #"*Please note, you cannot select the layout of the images within the grid at this time.";
footer.textColor = [UIColor blackColor];
footer.textAlignment = UITextAlignmentCenter;
footer.textAlignment = NSTextAlignmentCenter;
footer.tag = 10;
footer.backgroundColor = [UIColor clearColor];
footer.font = [UIFont systemFontOfSize:9.0f];
footer.hidden = NO;
footer.highlighted = YES;
footer.highlightedTextColor = [UIColor blackColor];
footer.lineBreakMode = YES;
footer.numberOfLines = 0;
//----------------
UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
CGSize divSize = CGSizeMake(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
UIImage *image = [[UIImage alloc] init];
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];
image = [imgArray objectAtIndex:0];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(200, 200, divSize.width-210, divSize.height-210)];
image = [imgArray objectAtIndex:1];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width, 200, divSize.width-210, divSize.height-210)];
image = [imgArray objectAtIndex:2];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(200, divSize.height, divSize.width-210, divSize.height-210)];
image = [imgArray objectAtIndex:3];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width, divSize.height, divSize.width-210, divSize.height-210)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
[viewImage setFrame:frame];
[scrollView addSubview:viewImage];
NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:#"RemoveIcon#2x" withExtension:#"png"];
UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
[self.removeButton setImage:buttonImage forState:UIControlStateNormal];
[self.removeButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.removeButton];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
}else if( nPageNum == 3 ){
int nVWidth, nVHeight;
nVWidth = self.view.frame.size.width;
nVHeight = (self.view.frame.size.height - 243) / 2;
CGRect frame;
frame.origin.x = 27.0f;
frame.origin.y = 65;
frame.size = CGSizeMake(269.5f, 253.5f);
NSMutableArray *imgArray = [NSMutableArray array];
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
[imgArray addObject:img1];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
UIImage *img2 = [[UIImage alloc] init];
img2 = subview.photo.image;
[imgArray addObject:img2];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
UIImage *img3 = [[UIImage alloc] init];
img3 = subview.photo.image;
[imgArray addObject:img3];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
UIImage *img4 = [[UIImage alloc] init];
img4 = subview.photo.image;
[imgArray addObject:img4];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:4];
UIImage *img5 = [[UIImage alloc] init];
img5 = subview.photo.image;
[imgArray addObject:img5];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:5];
UIImage *img6 = [[UIImage alloc] init];
img6 = subview.photo.image;
[imgArray addObject:img6];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:6];
UIImage *img7 = [[UIImage alloc] init];
img7 = subview.photo.image;
[imgArray addObject:img7];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:7];
UIImage *img8 = [[UIImage alloc] init];
img8 = subview.photo.image;
[imgArray addObject:img8];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:8];
UIImage *img9 = [[UIImage alloc] init];
img9 = subview.photo.image;
[imgArray addObject:img9];
NSURL *imageURL = [[NSBundle mainBundle] URLForResource:#"FramedBack" withExtension:#"png"];
frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
//Header Text above print
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
[self.view addSubview:headingLabel];
headingLabel.text = #"Time To Preview!";
headingLabel.textColor = [UIColor blackColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blackColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
//Footer Text under print
UILabel *footer = [[UILabel alloc] initWithFrame:CGRectMake(50, 330, 226, 50)];
[self.view addSubview:footer];
footer.text = #"*Please note, you cannot select the layout of the images within the grid at this time.";
footer.textColor = [UIColor blackColor];
footer.textAlignment = UITextAlignmentCenter;
footer.textAlignment = NSTextAlignmentCenter;
footer.tag = 10;
footer.backgroundColor = [UIColor clearColor];
footer.font = [UIFont systemFontOfSize:9.0f];
footer.hidden = NO;
footer.highlighted = YES;
footer.highlightedTextColor = [UIColor blackColor];
footer.lineBreakMode = YES;
footer.numberOfLines = 0;
//----------------
UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
CGSize divSize = CGSizeMake(IMAGE_WIDTH / 3, IMAGE_HEIGHT / 3);
UIImage *image = [[UIImage alloc] init];
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];
image = [imgArray objectAtIndex:0];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(210, 210, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:1];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width + 70, 210, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:2];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width * 2 - 70, 210, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:3];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(210, divSize.height + 70, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:4];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width + 70, divSize.height + 70, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:5];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width * 2 - 70, divSize.height + 70, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:6];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(210, divSize.height*2 -70, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:7];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width + 70, divSize.height*2 -70, divSize.width-150, divSize.height-150)];
image = [imgArray objectAtIndex:8];
image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
[image drawInRect:CGRectMake(divSize.width * 2 - 70, divSize.height*2 -70, divSize.width-150, divSize.height-150)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
[viewImage setFrame:frame];
[scrollView addSubview:viewImage];
NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:#"RemoveIcon#2x" withExtension:#"png"];
UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
[self.removeButton setImage:buttonImage forState:UIControlStateNormal];
[self.removeButton addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.removeButton];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
}else if( nPageNum == 4 ){
int nVWidth, nVHeight;
nVWidth = self.view.frame.size.width;
nVHeight = (self.view.frame.size.height - 243) / 2;
CGRect frame;
frame.origin.x = 27.0f;
// frame.origin.y = 23.0f;
frame.origin.y = 65;
frame.size = CGSizeMake(269.5f, 253.5f);
NSMutableArray *imgArray = [NSMutableArray array];
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
[imgArray addObject:img1];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
UIImage *img2 = [[UIImage alloc] init];
img2 = subview.photo.image;
[imgArray addObject:img2];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
UIImage *img3 = [[UIImage alloc] init];
img3 = subview.photo.image;
[imgArray addObject:img3];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
UIImage *img4 = [[UIImage alloc] init];
img4 = subview.photo.image;
[imgArray addObject:img4];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:4];
UIImage *img5 = [[UIImage alloc] init];
img5 = subview.photo.image;
[imgArray addObject:img5];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:5];
UIImage *img6 = [[UIImage alloc] init];
img6 = subview.photo.image;
[imgArray addObject:img6];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:6];
UIImage *img7 = [[UIImage alloc] init];
img7 = subview.photo.image;
[imgArray addObject:img7];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:7];
UIImage *img8 = [[UIImage alloc] init];
img8 = subview.photo.image;
[imgArray addObject:img8];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:8];
UIImage *img9 = [[UIImage alloc] init];
img9 = subview.photo.image;
[imgArray addObject:img9];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:9];
UIImage *img10 = [[UIImage alloc] init];
img10 = subview.photo.image;
[imgArray addObject:img10];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:10];
UIImage *img11 = [[UIImage alloc] init];
img11 = subview.photo.image;
[imgArray addObject:img11];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:11];
UIImage *img12 = [[UIImage alloc] init];
img12 = subview.photo.image;
[imgArray addObject:img12];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:12];
UIImage *img13 = [[UIImage alloc] init];
img13 = subview.photo.image;
[imgArray addObject:img13];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:13];
UIImage *img14 = [[UIImage alloc] init];
img14 = subview.photo.image;
[imgArray addObject:img14];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:14];
UIImage *img15 = [[UIImage alloc] init];
img15 = subview.photo.image;
[imgArray addObject:img15];
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:15];
UIImage *img16 = [[UIImage alloc] init];
img16 = subview.photo.image;
[imgArray addObject:img16];
Since the error is on the line:
[imgArray addObject:img1];
this means that img1 is nil. Since you get img1 from subview.photo.image this means one of three things:
subview.photo.image is nil.
subview.photo is nil.
subview is nil.
Since you just created subview then it probably isn't #3. Since you get subview.photo from:
[[IMLocalUser localUser] cachedPhotoAtIndex:0];
You should verify that this returns a non-nil value. If it is non-nil then verify the image property isn't nil.
Side note:
These two lines:
UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;
create a wasted UIImage. Just do:
UIImage *img1 = subview.photo.image;
Related
UIscrollView To scroll images horizontally and show images from the image clicked
I have four images on a viewcontroller.On the click of those images a newViewController i.e. LargeImageViewController opens. On the LargeImageViewController there is ScrollView which does horizontal scrolling. On click of every button the images on LargeImageViewController starts from image1 ,then shows image2,then image 3,then image 4. I want that if image 2 is clicked then the images on LargeImageViewController should start image2,then image 3,then image 4.....but when it goes to previous image then it should show image 4,image3,image 2 and image1 also. How this can be achieved?? Code that I am using are as follows: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // int pageCount=4; NSArray *imgArray = [self.tripDetails valueForKey:#"Flightimageurl"]; width = [UIScreen mainScreen].bounds.size.width; height = [UIScreen mainScreen].bounds.size.height; _scroller = [[UIScrollView alloc]initWithFrame: CGRectMake(0,64,width,height)]; _scroller.contentSize=CGSizeMake([imgArray count]*_scroller.bounds.size.width,_scroller.bounds.size.height); CGRect ViewSize=_scroller.bounds; for(int i=0;i<[imgArray count];i++) { UIImageView *imgView1=[[UIImageView alloc]initWithFrame:ViewSize]; NSString *ImageURL = [imgArray objectAtIndex:i]; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]]; imgView1.image=[UIImage imageWithData:imageData]; [_scroller addSubview:imgView1]; [self.view addSubview:_scroller]; ViewSize =CGRectOffset(ViewSize,_scroller.bounds.size.width,0); } } Kindly help with suggesting the changes.
-(void)singleTapping:(UIGestureRecognizer *)recognizer { int imageTag = (int) recognizer.view.tag; NSDictionary *dictCurrentWish = [arrLatestScrollData objectAtIndex:pageNumberSaved]; scrollimagePostView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, kSCREEN_WIDTH, kSCREEN_HEIGHT)]; scrollimagePostView.pagingEnabled=YES; scrollimagePostView.delegate=self; UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)]; [scrollimagePostView addGestureRecognizer:gr]; NSMutableArray *arrTotalImages = [[NSMutableArray alloc]initWithCapacity:0]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic1"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic2"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic3"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic4"]]; int x=0; CGRect innerScrollFrame = scrollimagePostView.bounds; for (int i=0; i<arrTotalImages.count; i++) { imgViewPost=[[UIImageView alloc]initWithFrame:CGRectMake(x, 60, kSCREEN_WIDTH,kSCREEN_HEIGHT-90)]; NSString *strImage =[NSString stringWithFormat:#"%#", [arrTotalImages objectAtIndex:i]]; NSString *strURL=[strImage stringByReplacingOccurrencesOfString:#" " withString:#"%20"]; NSURL* urlAddress1 = [[NSURL alloc] initWithString:strURL]; [imgViewPost sd_setImageWithURL:urlAddress1 placeholderImage:wishPlaceHolderImage]; imgViewPost.contentMode = UIViewContentModeScaleAspectFit; imgViewPost.tag = VIEW_FOR_ZOOM_TAG; UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame]; pageScrollView.minimumZoomScale = 1.0f; pageScrollView.maximumZoomScale = 6.0f; pageScrollView.zoomScale = 1.0f; pageScrollView.contentSize = imgViewPost.bounds.size; pageScrollView.delegate = self; pageScrollView.showsHorizontalScrollIndicator = NO; pageScrollView.showsVerticalScrollIndicator = NO; [pageScrollView addSubview:imgViewPost]; [scrollimagePostView addSubview:imgViewPost]; x=x+kSCREEN_WIDTH; if (i < 2) { innerScrollFrame.origin.x += innerScrollFrame.size.width; } } scrollimagePostView.contentSize = CGSizeMake(x, scrollimagePostView.frame.size.height ); scrollimagePostView.backgroundColor = [UIColor blackColor]; [self.view addSubview:scrollimagePostView]; [scrollimagePostView setContentOffset:CGPointMake(scrollimagePostView.frame.size.width*(imageTag-1), 0.0f) animated:NO]; btnCloseFullIMageView = [[UIButton alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH-80, 25, 70, 25)]; [btnCloseFullIMageView setTitle:#"Close" forState:UIControlStateNormal]; [btnCloseFullIMageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; btnCloseFullIMageView.backgroundColor = [UIColor blackColor]; btnCloseFullIMageView.layer.borderColor = [UIColor whiteColor].CGColor; btnCloseFullIMageView.layer.borderWidth = 0.5; btnCloseFullIMageView.layer.cornerRadius = 3.0; btnCloseFullIMageView.clipsToBounds = TRUE; [btnCloseFullIMageView addTarget:self action:#selector(closeFullImageView:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnCloseFullIMageView]; }
Images on horizontal scroll view according to clicked image
I have four images on a Viewcontroller A .On the click of those images Viewcontroller B having UIScrollView presents that has image view and it shows all those four imgaes....Image1 ,image 2,image 3,image 4. I want that when image 2 is clicked then image 2 appeas as the first image on Viewcontroller B ,then image 3,then image 4...Also,when user moves left then it shows previous images including image1 too. I have searched a lot but couldn't find solution to this problem Kindly.help The code I have used are as follows: - (void)viewDidLoad { [super viewDidLoad]; width = [UIScreen mainScreen].bounds.size.width; height = [UIScreen mainScreen].bounds.size.height; _scroller = [[UIScrollView alloc]initWithFrame: CGRectMake(0,64,width,height)]; _scroller.contentSize=CGSizeMake(pageCount*_scroller.bounds.size.width,_scroller.bounds.size.height); _scroller.pagingEnabled=YES; _scroller.showsHorizontalScrollIndicator=YES; CGRect ViewSize=_scroller.bounds; NSArray *imgArray = [self.tripDetails valueForKey:#"Flightimageurl"]; for(int i=0;i<[imgArray count];i++) { UIImageView *imgView1=[[UIImageView alloc]initWithFrame:ViewSize]; NSString *ImageURL = [imgArray objectAtIndex:i]; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]]; imgView1.image=[UIImage imageWithData:imageData]; [_scroller addSubview:imgView1]; [self.view addSubview:_scroller]; ViewSize =CGRectOffset(ViewSize,_scroller.bounds.size.width,0); } }
Use This Code It will be helpful to you -(void)singleTapping:(UIGestureRecognizer *)recognizer { int imageTag = (int) recognizer.view.tag; NSDictionary *dictCurrentWish = [arrLatestScrollData objectAtIndex:pageNumberSaved]; scrollimagePostView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, kSCREEN_WIDTH, kSCREEN_HEIGHT)]; scrollimagePostView.pagingEnabled=YES; scrollimagePostView.delegate=self; UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)]; [scrollimagePostView addGestureRecognizer:gr]; NSMutableArray *arrTotalImages = [[NSMutableArray alloc]initWithCapacity:0]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic1"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic2"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic3"]]; [arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic4"]]; int x=0; CGRect innerScrollFrame = scrollimagePostView.bounds; for (int i=0; i<arrTotalImages.count; i++) { imgViewPost=[[UIImageView alloc]initWithFrame:CGRectMake(x, 60, kSCREEN_WIDTH,kSCREEN_HEIGHT-90)]; NSString *strImage =[NSString stringWithFormat:#"%#", [arrTotalImages objectAtIndex:i]]; NSString *strURL=[strImage stringByReplacingOccurrencesOfString:#" " withString:#"%20"]; NSURL* urlAddress1 = [[NSURL alloc] initWithString:strURL]; [imgViewPost sd_setImageWithURL:urlAddress1 placeholderImage:wishPlaceHolderImage]; imgViewPost.contentMode = UIViewContentModeScaleAspectFit; imgViewPost.tag = VIEW_FOR_ZOOM_TAG; UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame]; pageScrollView.minimumZoomScale = 1.0f; pageScrollView.maximumZoomScale = 6.0f; pageScrollView.zoomScale = 1.0f; pageScrollView.contentSize = imgViewPost.bounds.size; pageScrollView.delegate = self; pageScrollView.showsHorizontalScrollIndicator = NO; pageScrollView.showsVerticalScrollIndicator = NO; [pageScrollView addSubview:imgViewPost]; [scrollimagePostView addSubview:imgViewPost]; x=x+kSCREEN_WIDTH; if (i < 2) { innerScrollFrame.origin.x += innerScrollFrame.size.width; } } scrollimagePostView.contentSize = CGSizeMake(x, scrollimagePostView.frame.size.height ); scrollimagePostView.backgroundColor = [UIColor blackColor]; [self.view addSubview:scrollimagePostView]; [scrollimagePostView setContentOffset:CGPointMake(scrollimagePostView.frame.size.width*(imageTag-1), 0.0f) animated:NO]; btnCloseFullIMageView = [[UIButton alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH-80, 25, 70, 25)]; [btnCloseFullIMageView setTitle:#"Close" forState:UIControlStateNormal]; [btnCloseFullIMageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; btnCloseFullIMageView.backgroundColor = [UIColor blackColor]; btnCloseFullIMageView.layer.borderColor = [UIColor whiteColor].CGColor; btnCloseFullIMageView.layer.borderWidth = 0.5; btnCloseFullIMageView.layer.cornerRadius = 3.0; btnCloseFullIMageView.clipsToBounds = TRUE; [btnCloseFullIMageView addTarget:self action:#selector(closeFullImageView:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnCloseFullIMageView]; }
UILabel not displaying after iOS 8.0 upgrade
Just updated to iOS 8.0 this morning. I have a piece of code which created some labels and displays them on the scree next to some images. It was working fine before the update. Now the label and the image is not displaying. Can some one please help as I have tried everything I can think of and nothing has solved my issue and couldn't find anyone else with a similar issue. Code attached below. UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)]; labelView.backgroundColor = [self colorWithHexString:#"2D2D2D"]; UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 200, kCategoryLabelHieght)]; categoryTitle.textAlignment = NSTextAlignmentLeft; categoryTitle.text = text; categoryTitle.font = [UIFont fontWithName:#"HelveticaNeue" size:14]; codeAppDelegate *appDelegate = (codeAppDelegate *)[[UIApplication sharedApplication] delegate]; NSArray *fetchedCategory = [appDelegate getCategoryByName:text]; UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 2, 20, 20)]; if(fetchedCategory.count) { for (int t=0; t<fetchedCategory.count; t++) { Dealcategory_List *catList = [fetchedCategory objectAtIndex:t]; NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.image]]; NSURL *url = [NSURL URLWithString:titleImage]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *imgTabs = [UIImage imageWithData:data]; // [header2 setImage:imgTabs forState:UIControlStateNormal]; [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(5, 10, 2, 0) resizingMode: UIImageResizingModeTile]; img.image= imgTabs; } } else { NSArray *fetchedNewsCategory = [appDelegate getNewsCategoryByName:text]; if(fetchedNewsCategory.count > 0) { for (int t=0; t<fetchedNewsCategory.count; t++) { News_Categories *catList = [fetchedNewsCategory objectAtIndex:t]; NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.category_image]]; NSURL *url = [NSURL URLWithString:titleImage]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *imgTabs = [UIImage imageWithData:data]; // [header2 setImage:imgTabs forState:UIControlStateNormal]; [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile]; img.image= imgTabs; } } else { NSArray *fetchedCompetition = [appDelegate getCompetitionByName:text]; if(fetchedCompetition.count > 0) { for (int t=0; t<fetchedCompetition.count; t++) { Competitions_List *catList = [fetchedCompetition objectAtIndex:t]; NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.competition_tab_image]]; NSURL *url = [NSURL URLWithString:titleImage]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *imgTabs = [UIImage imageWithData:data]; // [header2 setImage:imgTabs forState:UIControlStateNormal]; [imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile]; img.image= imgTabs; break; } } } } categoryTitle.textColor = color; [labelView addSubview:img]; [labelView addSubview:categoryTitle]; [self.contentView addSubview:labelView];
UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)]; You are defining a UIView but allocating a UILabel. iOS 8 is less tolerant to errors like this. Try to change it to UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];
Change image of a scrollview or replace the array of images
I have a problem with changing images in the scrollview, the scrollview problem is that depending on the action that makes me have to change the image that contains other, as I do not change the picture or the array of images, I need help, thanks - (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *imgNames = [[NSMutableArray alloc] initWithObjects:#"cooper.png", #"cabrio.png",#"country.png", nil]; NSMutableArray *imgArray = [[NSMutableArray alloc] init]; UIImageView *tempImageView; for(NSString *name in imgNames) { tempImageView = [[UIImageView alloc] init]; tempImageView.contentMode = UIViewContentModeScaleAspectFit; tempImageView.image = [UIImage imageNamed:name]; [imgArray addObject:tempImageView]; } CGSize pageSize = scrollView.frame.size; NSUInteger page = 0; for(UIView *view in imgArray) { [scrollView addSubview:view]; view.frame = CGRectMake(pageSize.width * page++ + 10, 0, pageSize.width - 20, pageSize.height); } scrollView.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height); } - (IBAction)btnAction:(id)sender { NSMutableArray *imgNames = [[NSMutableArray alloc] initWithObjects:#"hello.png", #"bye.png",#"trues.png", nil]; NSMutableArray *imgArray = [[NSMutableArray alloc] init]; UIImageView *tempImageView; for(NSString *name in imgNames) { tempImageView = [[UIImageView alloc] init]; tempImageView.contentMode = UIViewContentModeScaleAspectFit; tempImageView.image = [UIImage imageNamed:name]; [imgArray addObject:tempImageView]; } CGSize pageSize = scrollView.frame.size; NSUInteger page = 0; for(UIView *view in imgArray) { [scrollView addSubview:view]; view.frame = CGRectMake(pageSize.width * page++ + 10, 0, pageSize.width - 20, pageSize.height); } scrollView.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height); } }
You can directly set the image alone if UIImageView is already allocated in viewDidLoad like, for(UIImageView *view in imgArray) { view.image = [UIImage imageNamed:[imgNames objectAtIndex:[imgArray indexOfObject:view]]] }
iOS: cant view downloaded images
I'm a novice in this, so i would like to know what is missing in my code to download/show these images: self.carView.contentSize = CGSizeMake(280*self.carImages.count-280, 200); self.carView.pagingEnabled = YES; CGRect imageRect = CGRectMake(0.0, 0.0,280*self.carImages.count-280, 200); UIGraphicsBeginImageContext(imageRect.size); UIImageView *carImg = [[UIImageView alloc] init]; for (int i = 1; i < self.carImages.count; i++) { NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[self.carImages objectAtIndex:i]]]; UIImage *carImage = [[UIImage alloc] initWithData:imageData]; [carImage drawAtPoint:CGPointMake(280*(i-1), 0)]; [carImage release]; [imageData release]; NSLog(#"%d",i); } carImg.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self.carView addSubview:carImg]; [carImg release]; carView is my ScrollView. carImages is a MutableArray with the "URL" of the images. the pagingEnabled and contentSize are being set, but no images. I bet i'm missing something very stupid, as i allways do.