ObjC에서 작성한 처음 몇 개의 프로그램이 제대로 작동했지만 어지럽고 혼란스러워서 이번에는 제대로하고 MVC를 사용하고 싶었습니다. 모든 조각이 작동하고 테스트를 거쳤으며 뷰에서 VC를 통해 NSMutableArray를 모델에서 복사하려고 시도 할 때까지 모든 것이 잘 진행되었습니다. 정확한 형식과 코드가 사용되었고 프로그램의 다른 측면에서 잘 작동하지만이 특정 뷰는 drawRect를 사용하고 배열을 유지하지 않으면 중단됩니다. 내가 할 때 누출이 일어난다. 문제를 격리하고 대안을 만들려면 pList에서 직접 배열을로드해야합니다. 그것은 다음과 같습니다NSArray가 MVC 뷰에서 초기화되지 않습니다.
@interface HWView : UIView <UIGestureRecognizerDelegate>
{
NSMutableArray *drawStates;
}
@property (nonatomic, retain) NSMutableArray *drawStates;
을하는 .m
@implementation HWView
@synthesize drawStates;
- (void)awakeFromNib
{
[self HWVReset];
}
-(void)HWVReset
{
NSLog(@"HWVReset:");
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [documentsDirectorystringByAppendingPathComponent: @"PLIST_drawState.plist"];
self.drawStates = [[NSMutableArray arrayWithContentsOfFile:plistPath]retain];
NSLog(@"drawStates:%@",self.drawStates);
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
//draw code
}
- (void)dealloc
{
[self.drawStates release];
[super dealloc];
}
그래서이 실행하지만 누수에. 다음과 같이 retain을 제거합니다. "self.drawStates = [[NSMutableArray arrayWithContentsOfFile : plistPath] retain];" 그리고 그것은 충돌합니다. 어떤 도움을 주셔서 감사합니다.
어쩌면 당신은 보유 대신에 강해 져야할까요? –