Question

I have a UIViewController that is initialised with a correct frame, however somewhere in my code the frame gets mangled and I'm having difficulty finding out where.

In situations like this it is usually handy to watch a variable in the debugger, however I have no way of accessing the controller->view->frame property in my variable view, since it isn't a variable, it's a property (surprisingly enough)

Drilling into the UIView in the variables display shows a few things but nothing I can relate to the frame, I thought perhaps that would be in layer but it isn't.

Is there any way to watch for changes in a private API? I guess not, since the variables are essentially 'hidden' and so you can't specify exactly what to watch.

Alternatively, what other approach could I use? I already tried subclassing UIView, setting my UIViewController's view to point to this subclass and breaking on the setFrame method but it didn't seem to work.

EDIT: the subclassing UIView method DID work, I just had to set the view to point to my test subclass in viewDidLoad and not the init method. Leaving this question open as I'm not sure if this is the best way of approaching this kind of problem...

Was it helpful?

OTHER TIPS

Subclass your the view you want to track and rewrite the setFrame method:

@implementation MyTableView

- (void)setFrame:(CGRect)frame;
{
    NSLog(@"%@", frame);
    [super setFrame:frame];
}

@end

Then use the debugger to add a breakpoint to it and check when it gets called. Eventually, you'll see when the frame gets changed and where does the change comes from.

You could create an ivar, view2, and just assigned it to your view in your loadView method. That should enable you to watch it like a normal variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow