RESOLVED: Geezzz. After 3 hours of dealing with this, and the time to post the problem I discovered the problem. My iPhone is IOS6 and I was also testing it in the simulator which was IOS7. That line of code that was the problem worked fine in IOS7 because this method was introduced in IOS7 and did not exists in IOS6. So my code is fine in 7, but I am getting the error because that method is unavailable in 6. Lesson learned.
I have a Method that returns a UIImageView. The Method takes 3 arguments, a CGRect, Float for screen position and an NSString for what should be displayed.
Tonight I moved this Method to an NSObject Class that I use for repeat use and I started to get a EXC_BAD_Access crash. When I load from the internet and it takes time I wanted to use the UIActivityIndicatorView with some text above.
This is the code that calls the method.
When I set breakpoints to see if my arguments are nil, they are not, it is all there. I can't see how I am accessing deallocated memory since everything gets instantiated in this method or the objects are passed into this method which I can see by the breakpoints and they are not nil?
You can see in the photo breakpoints values and the error.
Thanks
I have a Method that returns a UIImageView. The Method takes 3 arguments, a CGRect, Float for screen position and an NSString for what should be displayed.
Tonight I moved this Method to an NSObject Class that I use for repeat use and I started to get a EXC_BAD_Access crash. When I load from the internet and it takes time I wanted to use the UIActivityIndicatorView with some text above.
Code:
+(UIImageView*)loadingView:(CGRect)rect yAxis:(float)yPos string:(NSString*)string{
UIImageView *returnView;
UIGraphicsBeginImageContext(rect.size);
UIActivityIndicatorView * progressView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
progressView.frame = CGRectMake(110, yPos, 100, 100);
progressView.tag = 102;
[progressView startAnimating];
CGContextRef context = UIGraphicsGetCurrentContext(); // Get blank Context.
CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 0.5f);
CGContextFillRect(context, rect);
UIFont *font = [UIFont fontWithName:@"Noteworthy-Bold" size:35.0];
CGRect fontRect = CGRectMake(100, yPos - 25, 300, 100);
UIColor *fontColor = [UIColor whiteColor];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName,[NSNumber numberWithFloat:1.0], NSBaselineOffsetAttributeName,fontColor, NSForegroundColorAttributeName, nil];
[COLOR="Red"][B][string drawInRect:fontRect withAttributes:attrsDictionary];[/B][/COLOR]
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
returnView = [[UIImageView alloc]initWithImage:newImage];
[returnView addSubview:progressView];
returnView.tag = 1010;
UIGraphicsEndImageContext();
return returnView;
}
This is the code that calls the method.
Code:
CGRect loadRect = CGRectMake(0, 0, self.view.frame.size.width, loadingSize);
[self.scrollView addSubview:[BoilerPlateCode loadingView:loadRect yAxis:800.0 string:@"Loading"]];
When I set breakpoints to see if my arguments are nil, they are not, it is all there. I can't see how I am accessing deallocated memory since everything gets instantiated in this method or the objects are passed into this method which I can see by the breakpoints and they are not nil?
You can see in the photo breakpoints values and the error.
Thanks
Attachments
Last edited: