iOS多级列表 - XQMultistageTableView
生活随笔
收集整理的這篇文章主要介紹了
iOS多级列表 - XQMultistageTableView
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
可以自定義子節點的多級菜單
1. 多級菜單
2. 多選/單選
3. 三種Cell樣式<Base 基礎、Default 默認、Custom 自定義>
Github XQMultistageTableView 地址
CocoaPods
pod 'XQMultistageTableView', '~> 1.0.6'XQMultistage 提供三種Cell樣式
1、Base 基礎
###使用 XQMultistageAdapter 管理適配器
- (void)viewDidLoad {[super viewDidLoad];_adapter = [[XQMultistageAdapter alloc] init];_adapter.radio = YES;_adapter.delegate = self;_adapter.multistageData = self.data;UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds];tableView.separatorStyle = UITableViewCellSeparatorStyleNone;tableView.dataSource = _adapter;tableView.delegate = _adapter;[self.view addSubview:tableView]; }##2、Default 默認
使用 XQMultistageAdapter 管理適配器
- (void)viewDidLoad {[super viewDidLoad];_adapter = [[XQMultistageDefaultAdapter alloc] init];_adapter.delegate = self;_adapter.multistageData = self.data;UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds];tableView.separatorStyle = UITableViewCellSeparatorStyleNone;tableView.dataSource = _adapter;tableView.delegate = _adapter;[self.view addSubview:tableView]; }3、Custom 自定義 ~隨心所欲 ~
使用 XQMultistageAdapter 管理適配器
- (void)viewDidLoad {[super viewDidLoad];_adapter = [[XQMultistageAdapter alloc] init];_adapter.radio = YES;_adapter.delegate = self;_adapter.multistageData = self.data;UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds];tableView.separatorStyle = UITableViewCellSeparatorStyleNone;tableView.dataSource = _adapter;tableView.delegate = _adapter;[self.view addSubview:tableView]; }通過 XQNode 設置對應的節點
typedef enum{ XQNodeContentTypeSuper, // 父節點 XQNodeContentTypeSub, // 子節點 }XQNodeContentType; @interface XQNode : NSObject #pragma 共同擁有 /// 節點名稱 @property(nonatomic, copy) NSString *title; /// 父節點的id,如果為-1表示該節點為根節點 @property (nonatomic , retain) NSNumber *parentId; /// 本節點的id @property (nonatomic , retain) NSNumber *nodeId; /// 該節點的深度 @property (nonatomic , assign) int depth; /// 使用者id @property (nonatomic , retain) NSNumber *userId; /// 內容類型 @property (nonatomic , assign) XQNodeContentType contentType; /// 圖片路徑 @property (nonatomic , copy) NSString *imagePath; #pragma Super /// 子節點列表 @property (nonatomic, strong) NSMutableArray *subItems; /// 該節點是否處于展開狀態 @property (nonatomic , assign) BOOL isExpand; @end#pragma mark - XQMultistageCellDelegate
/** 自定義Cell*/ - (XQMultistageCell *)xq_multistageAdapter:(XQMultistageAdapter *)adapter tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString * ID = @"QMultistage";CustomTypeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if (!cell) {cell = [[CustomTypeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];}return cell; }使用 CustomTypeViewCell 配置頁面
/*** 可以重寫 setting 方法,對Cell進行改造* 也可繼承 XQMultistageNode, 在使用時在轉換回自的 model*/ @implementation CustomTypeViewCell-(void)setNode:(XQMultistageNode *)node {[super setNode:node];// 此處..... }XQMultistageAdapterDelegate
// 是否關閉子節點 默認是 NO - (BOOL)xq_multistageAdapterShouldCloseSubNode:(XQMultistageAdapter *) adapter;// 父節點可不可以點擊 默認是 NO - (BOOL)xq_multistageAdapterUnClickSuperNode:(XQMultistageAdapter *) adapter;// cell 點擊事件 - (void)xq_multistageAdapter:(XQMultistageAdapter *) adapter didSelectRowAtNode:(XQMultistageNode *) node;// 選擇展示功能 -> 狀態改變 - (void)xq_multistageAdapter:(XQMultistageAdapter *) adapter didSelectStateChangeAtNode:(XQMultistageNode *) node selectState:(BOOL) state;// 行高 - (CGFloat)xq_multistageAdapter:(XQMultistageAdapter *) adapter heightForRowAtNode:(XQMultistageNode *) node;// 自定義 cell - (XQMultistageCell *)xq_multistageAdapter:(XQMultistageAdapter *) adapter tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;XQMultistageDefaultAdapterDelegate
// 自定義內容左邊內邊距 // 可通過 XQMultistageNode -> depth 獲取到當前層級決定縮緊長度 - (CGFloat)xq_multistageDefaultAdapterToContentLeftInset:(XQMultistageDefaultAdapter *) adapter;/** * 多級展示節點展開提示圖片功能代理 * 節點展開提示 是在 Cell 的左邊 */// 根節點展開提示圖片圖片 - (UIImage *)xq_multistageDefaultAdapterToRootExpandTipImage:(XQMultistageDefaultAdapter *) adapter;// 節點展開提示圖片圖片 - (UIImage *)xq_multistageDefaultAdapterToExpandTipImage:(XQMultistageDefaultAdapter *) adapter;// 根節點展開提示圖片 是否可以旋轉 - (BOOL)xq_multistageDefaultAdapterToRootExpandTipImageIsRotation:(XQMultistageDefaultAdapter *) adapter;/** * 多級展示選擇功能代理 * 節點選擇圖片是在 Cell 的右邊 */// 是否啟用選擇展示功能 配合 XQMultistageNode->selectState 使用 - (BOOL)xq_multistageDefaultAdapterToSelectOperation:(XQMultistageDefaultAdapter *) adapter;// 選擇展示功能 -> 選中狀態圖片 - (UIImage *)xq_multistageDefaultAdapterToImageStateSelected:(XQMultistageDefaultAdapter *) adapter;// 選擇展示功能 -> 未選中狀態圖片 - (UIImage *)xq_multistageDefaultAdapterToImageStateNormal:(XQMultistageDefaultAdapter *) adapter;Remind
ARC iOS>=6.0 iPhone \ iPad screen anywayXQKit 交流:546456937
總結
以上是生活随笔為你收集整理的iOS多级列表 - XQMultistageTableView的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows10与windows98虚
- 下一篇: 如何解决eclipse黑底白字快速需求