Search code examples
iosdrawrectself

Draw rect causing errors, can't reference myview


Here is my code. I'm trying to access the frame of my view. First i nslog self, to make sure the view is allocated, and then i try to nslog the frame of my view, it returns null. Code:

- (void)drawRect:(CGRect)rect {
    NSLog(@"%@",self);
    CGRect frameads = self.frame;
    NSLog(@"%@",frameads);
}

Compiler output:

2012-07-18 11:41:59.808 animation[74551:f803] <MyView: 0x68568e0; frame = (0 37; 320 321); autoresize = RM+BM; layer = <CALayer: 0x6856a50>>
2012-07-18 11:41:59.808 animation[74551:f803] (null)

Solution

  • frame is a struct (CGRect) so wont be logged using %@, use

    NSLog(@"%@", NSStringFromCGRect(self.frame));