0
NSCell의 하위 클래스를 만들고 setObjectValue 함수를 재정 의하여 내 needs.Things가 누수 문제가있는 것을 제외하고는 괜찮습니다. NSCell의 setObjectValue 함수는 원래 객체를 공개하지 않습니다.NSTableView의 코코아 사용자 지정 셀 : NSCell 서브 클래 싱 누설
내가 수업을주는 목적은 NSCopying 프로토콜을 준수하고
- (void)setObjectValue:(id <NSCopying>)object {
// I tried to use [[self objectValue] release]; here but the app crashed
[super setObjectValue:object];
//---- other iniatizlize here ---
}
아래로 copyWithZone 기능을 구현 사용자 정의 개체입니다.
- (id)copyWithZone:(NSZone *)zone {
MapComponent *newCopy = [[MapComponent allocWithZone:zone] initWithType:self.componentType];
newCopy.myImage = self.myImage;
return newCopy;
}
나는 동일한 문제를 발견했습니다 here. 대답은 없지만 제 상황을 더 잘 표현할 수 있습니다.
당신은 복사 방식에서'autorelease' 값을 반환하지한다! – Richard
또 다른 문제는 초기에 동일한 ** 포인터 값 **에'self.myImage'가있는 접근 자'newCopy.myImage'를 사용하고 있다는 것입니다. 당신이 원하는 것은 직접적인 포인터 접근이다 :'newCopy-> myImage = nil; newCopy.myImage = self.myImage;'newCopy는 self의 myImage가 복사본을 만들려고 할 때 그것을 release합니다. – Richard