Я хотел бы загрузить экземпляры класса, содержащего uibezierPath, и перерисовать эти предыдущие пути при запуске приложения. Словарь возвращает правильные экземпляры, но я не могу рисовать пути: представление создается в раскадровке, поэтому я использовал initWithCoder, если я использую viewDidLoad, этот метод не вызывается. И ошибка:cgcontext серьезная ошибка: draw bezierPath в initwithcoder?
previousArrays : ( { firstPath = ""; }, { firstPath = ""; }, { firstPath = ""; }, { firstPath = ""; } ) Dec 30 17:02:36 iPhone MyProject[1818] : CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Вот мой код:.. (После прикосновения, путь сохраняется, то при повторном запуске приложения появляется ошибка Когда я рисую, хотя, нет никаких проблем Рисуют путь работает это при возврате к приложению, и рисунок в initWithCoder, что появляется проблема)
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithCGPath:myPath];//nscoding compliant
DataForPath *firstPath = [[DataForPath alloc] init];
firstPath.path = bezierPath;
firstPath.colorInArray = @(currentColor);
NSDictionary *dict = @{@"firstPath":firstPath};
[SaveData saveData:dict];
}
-(id)initWithCoder:(NSCoder *)aDecoder{
if (!(self=[super initWithCoder:aDecoder])) return nil;
//...
myPath = CGPathCreateMutable();
CGContextRef context = UIGraphicsGetCurrentContext();
NSArray *previousArrays = [SaveData loadData];
//NSLog("previousArrays : %@", previousArrays)...
for (NSDictionary*dict in previousArrays){
UIBezierPath *eachPath = dict[@"path"];
int color = [dict[@"colorInArray"] intValue];
UIColor *objectColor = [self.possibleColor objectAtIndex:color];
CGContextAddPath(context, eachPath.CGPath);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextDrawPath(context, kCGPathStroke);
/*
CGContextSetStrokeColorWithColor(context, objectColor.CGColor);
CGContextSaveGState(context);
[eachPath stroke];
CGContextRestoreGState(context);
*/
}
return self;
}
EDIT:.. предыдущие пути в цикл не нарисованы?
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
if (firstLaunchWithPreviousPaths){
for (NSDictionary*dict in previousArrays){
NSLog(@"firstLaunch"); //is called
UIBezierPath *eachPath = dict[@"path"];
CGContextAddPath(context, eachPath.CGPath);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextDrawPath(context, kCGPathStroke);
//nothing is drawn?
}
}
//with touchesEnd : this works
/*
CGContextAddPath(context, myPath);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextDrawPath(context, kCGPathStroke);
*/
}
Спасибо, хорошо, мне нужно исправить некоторые проблемы, но я думаю, что это решает одну проблему. Спасибо – Paul
Да, я думаю, теперь вы сможете легко отследить эти другие проблемы с помощью хорошей регистрации/отладки. – matt