【发布时间】:2011-07-21 11:46:06
【问题描述】:
该应用程序在 iphone 模拟器上运行良好,但是当我们在实际的 iphone 设备上运行它时,它会在以下行崩溃:
[ucdView.image drawInRect:rect];
我已经搜索并找到了解决方案,但我不知道如何解决,因为时间很短,我们必须在本周五展示它。看下面的解决方案: Must drawInRect: for a separate context be executed on the main thread?
发生这种崩溃的部分是在 viewDidLoad() 中的 Sculpture.m 中
- (void)viewDidLoad{
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
currentLoc = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redPin.png"]];
UIImage *ucdImage = [UIImage imageNamed:@"ucd.png"];
self.ucdView = [[UIImageView alloc] initWithImage:ucdImage];//creating a view for UCD image
ucdView.userInteractionEnabled = YES;
[self loadingFile];
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[myScrollView setMinimumZoomScale:0.35];
[myScrollView setMaximumZoomScale:2.0];
myScrollView.clipsToBounds = YES;
myScrollView.bounces = YES;
myScrollView.contentOffset = CGPointMake(1400, 700);
[myScrollView setContentSize:CGSizeMake(ucdImage.size.width, ucdImage.size.height)];
[myScrollView setDelegate:self];
[myScrollView addSubview:ucdView];//adding ucd view to scroll view
[self.view addSubview:myScrollView]; // adding scrollview to self.view main view
[myScrollView release];
//Drawing The Line
UIGraphicsBeginImageContext(ucdView.frame.size);
CGRect rect = CGRectMake(0, 0, ucdView.frame.size.width, ucdView.frame.size.height);
[ucdView.image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGFloat dashArray[] = {2,0,2,2};
CGContextSetLineDash(context, 3, dashArray, 5);
CGContextMoveToPoint(context,[self longt_to_x:[[path_array objectAtIndex:0] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:1] doubleValue]]);
int path_length = [path_array count];
for(int i = 2; i<path_length; i = i+2){
CGContextAddLineToPoint(context,[self longt_to_x:[[path_array objectAtIndex:i] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:i+1] doubleValue]]);
}
CGContextStrokePath(context);
ucdView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
提前一百万谢谢...
【问题讨论】:
-
你能提供崩溃日志吗,它会帮助你解决问题。
标签: iphone objective-c cocoa-touch crash drawrect