开发者

calling frame on UIView gives EXC_BAD_ACCESS

开发者 https://www.devze.com 2023-04-11 02:29 出处:网络
This is a weird behavior that I just can\'t u开发者_如何学JAVAnderstand: I access my own subclassed UIViews like this:

This is a weird behavior that I just can't u开发者_如何学JAVAnderstand:

I access my own subclassed UIViews like this:

    UIView *aZettel = [self.view viewWithTag:100]; 
    NSLog(@"aZettel %@", aZettel);

The view I'm calling is my own class, it's an UIView containing one UIImageView and one UILabel. NSLog shows:

    2011-10-04 09:45:35.969 accessapp[11264:207] aZettel <Zettel: 0x534b1c0; frame = (88 103; 160 106); tag = 100; layer = <CALayer: 0x534abc0>>

but when I write NSLog(@"aZettel %@", aZettel.frame); the app crashes with EXC_BAD_ACCESS on the line with NSLog. Zombies says nothing.

I wouldn't ask if I hadn't already wasted almost one day with this. The longer I try stuff with trial and error the more confused I get. Anybody a hint what could be causing this?


Your program crashes because in

NSLog(@"aZettel %@", aZettel.frame);

NSLog expects its parameter to be valid object, while you pass c-struct to it (CGRect). Convert CGRect to NSString to log it:

NSLog(@"aZettel %@", NSStringFromCGRect(aZettel.frame));
0

精彩评论

暂无评论...
验证码 换一张
取 消