首页 > 代码库 > iOS 8:帮妹子调试第三方库 - RATreeView

iOS 8:帮妹子调试第三方库 - RATreeView

关键字:RATreeView  妹子

周日晚上遇到一妹子用RATreeView(GitHub链接),想改变二级Cell高度。这库我也没接触过,但是,对方是妹子,明天还要交差,那就硬着头皮看代码吧。没想到此库结构非常清晰,真是业界良心。现在老了,很多事做完就忘,当是日志写写。下面记录下查找问题的过程。

1、先运行demo。如果跑不起来,那真是坑爹了。不过,免费的东西,也别要求太多,有代码就挺厚道的,毕竟提供了参考。demo被妹子改过,还好功能较单一。

2、看AppDelegate,找rootViewController。

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2 { 3     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 4   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 5       self.viewController = [[RAViewController alloc] initWithNibName:@"RAViewController_iPhone" bundle:nil]; 6   } else { 7       self.viewController = [[RAViewController alloc] initWithNibName:@"RAViewController_iPad" bundle:nil]; 8   } 9   self.window.rootViewController = self.viewController;10     [self.window makeKeyAndVisible];11     return YES;12 }

从代码可知,RAViewController为根控制器。

3、找RAViewController的viewDidLoad、viewWillAppear等生命周期方法。在viewDidLoad中找到如下代码:

 1   RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.frame]; 2    3   treeView.delegate = self; 4   treeView.dataSource = self; 5   treeView.separatorStyle = RATreeViewCellSeparatorStyleSingleLine; 6    7   [treeView reloadData]; 8   [treeView expandRowForItem:phone withRowAnimation:RATreeViewRowAnimationNone]; //expands Row 9   [treeView setBackgroundColor:[UIColor redColor]];10   11   self.treeView = treeView;

RAViewController只覆盖了viewDidLoad,可知,应用呈现出来的视图即是11行self.treeView = treeView的操作结果。

4、受经验影响,查找heightFor方法,找到treeView:heightForRowForItem:treeNodeInfo:返回值为CGFloat,那基本是它在控制高度了。

 1 #pragma mark TreeView Delegate methods 2 - (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo 3 { 4     if (treeNodeInfo.treeDepthLevel == 0) { 5         return 100; 6     }if (treeNodeInfo.treeDepthLevel == 1 && treeNodeInfo.siblingsNumber == 0) { 7         return 20; 8     } 9     return 47;10 }

妹子想控制二级Cell高度,那第6行代码if (treeNodeInfo.treeDepthLevel == 1 && treeNodeInfo.siblingsNumber == 0)应该是判断二级cell,果断改之,新代码如下:

 1 #pragma mark TreeView Delegate methods 2 - (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo 3 { 4     if (treeNodeInfo.treeDepthLevel == 0) { 5         return 100; 6     }if (treeNodeInfo.treeDepthLevel == 1/*&&treeNodeInfo.siblingsNumber == 0*/) { 7         if ([item isKindOfClass:[RADataObject class]]){ 8             RADataObject *dataObject = (RADataObject*)item; 9             if ([dataObject.name isEqualToString:@"Phone 1"]) {10                 return 150;11             }12         }13         return 20;14     }15     return 47;16 }

示例代码,硬编码,懒得搞,运行后妹子一看,得,就这个味。好,继续看《国土安全》。

总结:有毛线总结。

iOS 8:帮妹子调试第三方库 - RATreeView