2013-05-30 1 views
-1

UIExpandableTableView - https://github.com/OliverLetterer/UIExpandableTableView#readme을 사용하고 싶습니다.initWithFrame으로 작성된 클래스 - 스토리 보드에서 인스턴스화하려고합니다.

나는 단지 초기화가 initWithFrame입니다 때문에 문제로 실행했습니다

#pragma mark - Initialization 

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style { 
    if ((self = [super initWithFrame:frame style:style])) { 
     self.maximumRowCountToStillUseAnimationWhileExpanding = NSIntegerMax; 
     self.expandableSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.showingSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.downloadingSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.animatingSectionsDictionary = [NSMutableDictionary dictionary]; 
    } 
    return self; 
} 

나는 스토리 보드에서있는 tableView를 초기화하려고했는데이 initWithFrame이 결코 없기 때문에 제가 보는 오류가 있습니다 실현 호출되고 NSMutableDictionaries은 초기화되지 않습니다. 어떻게 해결할 수 있을까요?

간단히 해결할 수없는 경우 프로그래밍 방식으로 인스턴스화하고 initWithFrame과 함께 할 수 있지만 Storyboard를 사용하려는 외에 솔루션이 무엇인지 궁금합니다. 여기


편집 이러한 속성과 인스턴스 변수가 UIExpandableTableView에 선언하는 방법이다. 이것은 .H 파일에 있습니다

@interface UIExpandableTableView : UITableView <UITableViewDelegate, UITableViewDataSource, NSCoding> { 

@private ID __UIExpandableTableView_weak _myDelegate; id __UIExpandableTableView_weak _myDataSource;

NSMutableDictionary *_expandableSectionsDictionary;  // will store BOOLs for each section that is expandable 
NSMutableDictionary *_showingSectionsDictionary;  // will store BOOLs for the sections state (nil: not expanded, 1: expanded) 
NSMutableDictionary *_downloadingSectionsDictionary; // will store BOOLs for the sections state (nil: not downloading, YES: downloading) 
NSMutableDictionary *_animatingSectionsDictionary; 

NSInteger _maximumRowCountToStillUseAnimationWhileExpanding; 

BOOL _onlyDisplayHeaderAndFooterViewIfTableViewIsNotEmpty; 
UIView *_storedTableHeaderView; 
UIView *_storedTableFooterView; 

}

여기 UIExpandableTableView의하는 .m 파일의 맨입니다. T

@interface UIExpandableTableView() 

@property (nonatomic, retain) NSMutableDictionary *expandableSectionsDictionary; 
@property (nonatomic, retain) NSMutableDictionary *showingSectionsDictionary; 
@property (nonatomic, retain) NSMutableDictionary *downloadingSectionsDictionary; 
@property (nonatomic, retain) NSMutableDictionary *animatingSectionsDictionary; 

@property (nonatomic, retain) UIView *storedTableHeaderView; 
@property (nonatomic, retain) UIView *storedTableFooterView; 

- (void)downloadDataInSection:(NSInteger)section; 

- (void)_resetExpansionStates; 

@end 

답변

0

나는 다음을 수행 할 것 :

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style { 
    if ((self = [super initWithFrame:frame style:style])) { 
     [self setup]; 
    } 
    return self; 
} 

- (void)awakeFromNib { 
    [super awakeFromNib]; 
    [self setup]; 
} 

- (void)setup { 
    self.maximumRowCountToStillUseAnimationWhileExpanding = NSIntegerMax; 
    self.expandableSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.showingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.downloadingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.animatingSectionsDictionary = [NSMutableDictionary dictionary]; 
} 
1

당신이해야 할 모든 initWithFrame:를 제거하고 대신 initWithCoder:를 오버라이드 (override)합니다. 이 메소드는 인터페이스 빌더 요소가 init에 도달하여 사전 설정을 허용 할 때 호출됩니다. 그리고 두 경우 모두 인터페이스 빌더에서 처리되기 때문에 스타일 및 프레임 인수를 제거하는 것에 대해 걱정할 필요가 없습니다.

- (id)initWithCoder:(NSCoder *)aDecoder 
{ 
    if (self = [super initWithCoder:aDecoder]) { 
     NSLog(@"%s",__PRETTY_FUNCTION__); // Proof of call 
     self.maximumRowCountToStillUseAnimationWhileExpanding = NSIntegerMax; 
     self.expandableSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.showingSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.downloadingSectionsDictionary = [NSMutableDictionary dictionary]; 
     self.animatingSectionsDictionary = [NSMutableDictionary dictionary]; 
    } 
    return self; 
} 
+0

이것은 쉬운 해결책 인 것처럼 보이지만 일반적으로 제 3 자 코드를 복사하고 변경하는 대신 서브 클래 싱하는 것이 좋습니다. 그런 생각을 잘못 했나요? – Ramsel

+0

@SmoothAlmonds 나는 변화를 만드는 법을 보여 주려고했지만, 당신이 옳았다면, 하위 클래스를 만드는 것이 더 좋을 것이다. –

1

당신이 UIExpandableTableView에서 서브 클래스 및

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style { 
    if (self = [super initWithFrame:frame style:style]) { 
     [self configure]; 
    } 
    return self; 
} 


-(id)initWithCoder:(NSCoder *)aCoder { 
    if(self = [super initWithCoder:aCoder]){ 
     [self configure]; 
    } 
    return self; 
} 


-(void) configure { 
    self.maximumRowCountToStillUseAnimationWhileExpanding = NSIntegerMax; 
    self.expandableSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.showingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.downloadingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.animatingSectionsDictionary = [NSMutableDictionary dictionary]; 
} 

빻을하고 Storybord 인스턴스화가 initWithCoder:

Subcalssing를 통해 돈입니다 수는이 경우 타사 코드 패치를 사용할 수 있습니다.

+0

그래서 이것을 솔루션으로 생각하고 시도해 보았습니다. 그러나 내 속성에 오류가 발생했습니다. 따라서 UIExpandableTableView는 위의 편집에 표시된대로 구현 파일의 인터페이스에 나열된 속성을 갖습니다. 서브 클래스의'type ... of object ...에 프로퍼티를 찾을 수 없습니다. '라는 메시지가 나타납니다.내 하위 클래스의 해당 속성에 액세스 할 수있는 방법이 있습니까? – Ramsel

+0

.h 파일에 선언 된 비공개 ivars가 있습니다. 편집에 포함 시켰습니다. – Ramsel

+0

다시 선언하십시오. – vikingosegundo

0

이것은 가장 간단한 해결책이라고 생각합니다. 뷰 컨트롤러가 초기화되는 방법에 대해 걱정할 필요가 없습니다.

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.maximumRowCountToStillUseAnimationWhileExpanding = NSIntegerMax; 
    self.expandableSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.showingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.downloadingSectionsDictionary = [NSMutableDictionary dictionary]; 
    self.animatingSectionsDictionary = [NSMutableDictionary dictionary]; 
} 
관련 문제