필터 구현을 좀 더 보여줍니다. 속성을 설정하지 못하게하는 많은 것들이있을 수 있습니다. 가장 중요한 사실은 그것이 당신의 공개 인터페이스에 없다는 사실입니다.
@interface Filter : NSObject
@property (nonatomic, assign) BOOL name;
@property (nonatomic, assign) BOOL virtualRoomSet;
@end
차이를 두지는 않지만 개체의 의도를 명확하게해야합니다.
#import "Filter.h"
@implementation NavigationController
@property (nonatomic, retain) Filter *filter;
@end
@implementation NavigationController
@synthesize filter;
//assuming you've properly alloced in init...
-(void) dealloc
{
[filter release];
[super dealloc];
}
- (IBAction)setVirtualShowProperty:(UISwitch*)sender {
self.filter.virtualRoomSet = YES; //better syntax as dealing directly w/ iVars is error prone
}
@end
속성을 사용하는 대신 인스턴스 변수에 액세스하는 직접 작성해야 메모리 MGMT 코드의 양을 줄이고 필요한 객체를 협력 승/인스턴스 변수를 대체 할 수있는 기능을 제공합니다 : 컨트롤러 구현에 관한. 필자는 현재 암시 적으로 가정 된 이후로 함께 iVars를 함께 선언하지 않습니다. 그러면 "@synthesize myVar = _myVar;"에서 벗어날 수 있습니다. 추함.
당신은 당신의 필터에서이 같은 경우 : 필터 구현
@interface Filter : NSObject {
BOOL _virtualRoomSet;
}
@property (nonatomic, assign) BOOL name;
@property (nonatomic, assign) BOOL virtualRoomSet;
@end
그리고이 :
@implementation Filter
@synthesize filter;
//other code
@end
... 그것은 더 이상 내 점을 강조 버그를 설명 할 수를 iVars 선언을 피하는 방법! 즉, 실제로 설정하려는 것을 설정하고 있는지 확인하십시오. 암시 적 iVar는 이제 iOS SDK 3.0 이후 또는 모든 버전에서 자동으로 선언됩니다. 엄지 손가락의 규칙, 코드에서 iVars를 죽이고 속성 만 처리하십시오.
virtualRoomSet은 어디에 정의되고 어떻게 구성됩니까? – rooftop
이름 및/또는 virtualRoomSet이 오타입니까? –
'필터 '를 초기화하셨습니까? –