views:

183

answers:

1

A few weeks ago I found somewhere a code that allows one to dump to the terminal, using NSLOG, a hierarchic list of all view, subviews and objects created by an application, but I cannot find this code anymore?

Do you guys know how to do that?

thanks in advance for any help!

+2  A: 

I have a category that adds the following method to UIView for this sort of thing:

- (NSArray *) allSubviews {
    NSMutableArray    *subviews = [self.subviews mutableCopy];

    for (UIView *view in self.subviews) {
     [subviews addObjectsFromArray: [view allSubviews]];
    }
    return subviews;
}

You can then NSLog() the returned array. Alternatively, for a little more detail, you could use the following:

- (NSString *) hierarchyToStringWithLevel: (int) level {
    NSMutableString    *results = [NSMutableString stringWithString: @"\n"];

    for (int i = 0; i < level; i++) {
     [results appendFormat: @"-\t"];
    }

    [results appendFormat: @"[%@, 0x%X], %@", [self class], self, NSStringFromCGRect(self.frame)];
    for (UIView *child in self.subviews) {
     [results appendFormat: @"%@", [child hierarchyToStringWithLevel: level + 1]];
    }
    return results;
}
Ben Gottlieb
that's it! Thanks!!!!!
Digital Robot