我想使用UIExpandableTableView - https://github.com/OliverLetterer/UIExpandableTableView#readme。使用initWithFrame編寫的類 - 我想從Storyboard實例化
我碰到的一個問題,因爲它是唯一的初始化是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之外,我也很好奇解決方案是什麼。
編輯 這裏是如何將這些屬性和它們的ivars在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文件的頂部。牛逼
@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
因此,這似乎是一個簡單的解決方案,但是不是一般的第三方代碼的好習慣,而不是複製它並改變它?我錯在認爲? – Ramsel
@SmoothAlmonds我只是在演示如何進行更改,但你是對的,最好做一個子類。 –