2010-11-12 16 views

cevap

41

ben tam DebugPrintControlHierarchy baskılı bilmiyorum ama NSView yararlı bir yöntem çağrısı alıcı altındaki tüm hiyerarşiyi açıklayan bir dize döndürür _subtreeDescription sahiptir, sınıflar, çerçeveler ve diğer yararlı bilgileri içerir.

Önde gelen _ alt çizgisinden korkmayın. Kamu API'sı değil, gdb'de kamu kullanımı için onaylandı. Bazı örnek çıktıları ile birlikte in the AppKit release notes numaralı telefonu görebilirsiniz.

5

Burada bir süre geri inşa NSView kategorisinin bağırsaklar var: Bir NSView kategoride

Dökümü bu

+ (NSString *)hierarchicalDescriptionOfView:(NSView *)view 
             level:(NSUInteger)level 
{ 

    // Ready the description string for this level 
    NSMutableString * builtHierarchicalString = [NSMutableString string]; 

    // Build the tab string for the current level's indentation 
    NSMutableString * tabString = [NSMutableString string]; 
    for (NSUInteger i = 0; i <= level; i++) 
    [tabString appendString:@"\t"]; 

    // Get the view's title string if it has one 
    NSString * titleString = ([view respondsToSelector:@selector(title)]) ? [NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"\"%@\" ", [(NSButton *)view title]]] : @""; 

    // Append our own description at this level 
    [builtHierarchicalString appendFormat:@"\n%@<%@: %p> %@(%li subviews)", tabString, [view className], view, titleString, [[view subviews] count]]; 

    // Recurse for each subview ... 
    for (NSView * subview in [view subviews]) 
    [builtHierarchicalString appendString:[NSView hierarchicalDescriptionOfView:subview 
                      level:(level + 1)]]; 

    return builtHierarchicalString; 
} 

- (void)logHierarchy 
{ 
    NSLog(@"%@", [NSView hierarchicalDescriptionOfView:self 
               level:0]); 
} 

Kullanımı, içinde bu dökümü. Kullanmak istediğiniz yerdeki kategori başlığını ekleyin, ardından [myView logHierarchy]; numaralı telefonu arayın ve izleyin.

2

Swift 4.

MacOS:

extension NSView { 

    // Prints results of internal Apple API method `_subtreeDescription` to console. 
    public func dump() { 
     Swift.print(perform(Selector(("_subtreeDescription")))) 
    } 
} 

IOS: (ayıklayıcısında)

extension UIView { 

    // Prints results of internal Apple API method `recursiveDescription` to console. 
    public func dump() { 
     Swift.print(perform(Selector(("recursiveDescription")))) 
    } 
} 

Kullanım: po myView.dump()

İlgili konular