zetasq
11/20/2015 - 6:22 AM

ZSDoubleCascadeTableView.h

//
//  ZSDoubleCascadeTableView.h
//
//  Created by ZhuShengqi on 25/9/15.
//  Copyright © 2015 9tong. All rights reserved.
//

#import <UIKit/UIKit.h>
@class ZSDoubleCascadeTableView;

@protocol ZSDoubleCascadeTableViewDatasource <NSObject>

@required
- (NSInteger)tableView:(nonnull ZSDoubleCascadeTableView *)tableView numberOfParentCellsAtSection:(NSInteger)section;
- (NSInteger)tableView:(nonnull ZSDoubleCascadeTableView *)tableView numberOfChildCellsAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (nonnull UITableViewCell *)tableView:(nonnull ZSDoubleCascadeTableView *)tableView parentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section isExpanded:(BOOL)expanded;
- (nonnull UITableViewCell *)tableView:(nonnull ZSDoubleCascadeTableView *)tableView childCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;


@optional
- (NSInteger)numberOfSectionsInTableView:(nonnull ZSDoubleCascadeTableView *)tableView;
- (NSArray<NSString *> * _Nullable)sectionIndexTitlesForTableView:(ZSDoubleCascadeTableView * _Nonnull)tableView;

- (NSString * _Nullable)tableView:(nonnull ZSDoubleCascadeTableView *)tableView titleForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(nonnull ZSDoubleCascadeTableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(nonnull ZSDoubleCascadeTableView *)tableView heightForFooterInSection:(NSInteger)section;
- (CGFloat)tableView:(nonnull ZSDoubleCascadeTableView *)tableView heightForParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (CGFloat)tableView:(nonnull ZSDoubleCascadeTableView *)tableView heightForChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;

@end

@protocol ZSDoubleCascadeTableViewDelegate <NSObject>
@optional
- (BOOL)tableView:(nonnull ZSDoubleCascadeTableView *)tableView shouldSelectParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (BOOL)tableView:(nonnull ZSDoubleCascadeTableView *)tableView shouldExpandParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (BOOL)tableView:(nonnull ZSDoubleCascadeTableView *)tableView shouldSelectChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView willExpandParentCell:(nonnull UITableViewCell *)cell atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView willShrinkParentCell:(nonnull UITableViewCell *)cell atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView didSelectParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView didSelectChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView didDeselectParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;
- (void)tableView:(nonnull ZSDoubleCascadeTableView *)tableView didDeselectChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section;

// ScrollView Methods
- (void)scrollViewWillBeginDragging:(nonnull UIScrollView *)scrollView;

@end

@interface ZSDoubleCascadeTableView : UITableView

@property (nonatomic, weak) id<ZSDoubleCascadeTableViewDatasource> zsDatasource;
@property (nonatomic, weak) id<ZSDoubleCascadeTableViewDelegate> zsDelegate;

- (void)reloadWithPreviousCascadeState; 
- (void)reloadWithCompactState;

- (void)selectParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
- (void)deselectParentCellAtParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section animated:(BOOL)animated;
- (void)selectChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
- (void)deselectChildCellAtChildIndex:(NSInteger)childIndex atParentIndex:(NSInteger)parentIndex atSection:(NSInteger)section animated:(BOOL)animated;

- (nonnull instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;

@end