是否有视图控制器层次结构的recursiveDescription方法? [英] Is there a recursiveDescription method for the view controller hierarchy?
问题描述
recursiveDescription
非常有用。查看控制器层次结构也非常重要,是否有相应的内容?
recursiveDescription
is very useful when debugging a hierarchy of views. View controller hierarchies are also very important, is there an equivalent for this?
推荐答案
更新 - 类似的功能现在以Apple提供的形式提供,只需 _printHierarchy
方法,因此您不再需要此类别。
Update - similar functionality is now available in Apple-supplied form as the _printHierarchy
method, so you don't need this category any more.
现在有:
这会添加 recursiveDescription
方法到 UIViewController
,它打印出视图控制器层次结构。非常适合检查您是否正确添加和删除子视图控制器。
This adds a recursiveDescription
method to UIViewController
which prints out the view controller hierarchy. Excellent for checking if you are adding and removing your child view controllers properly.
代码非常简单,包括在这里以及上面的GitHub链接:
The code is very simple, included here as well as the GitHub link above:
@implementation UIViewController (RecursiveDescription)
-(NSString*)recursiveDescription
{
NSMutableString *description = [NSMutableString stringWithFormat:@"\n"];
[self addDescriptionToString:description indentLevel:0];
return description;
}
-(void)addDescriptionToString:(NSMutableString*)string indentLevel:(NSInteger)indentLevel
{
NSString *padding = [@"" stringByPaddingToLength:indentLevel withString:@" " startingAtIndex:0];
[string appendString:padding];
[string appendFormat:@"%@, %@",[self debugDescription],NSStringFromCGRect(self.view.frame)];
for (UIViewController *childController in self.childViewControllers)
{
[string appendFormat:@"\n%@>",padding];
[childController addDescriptionToString:string indentLevel:indentLevel + 1];
}
}
@end
这篇关于是否有视图控制器层次结构的recursiveDescription方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!