views:

346

answers:

2

Whenever I execute the code below I always get button type = 0 no matter what I specify for buttonWithType. Does anyone know an explanation for this behavior? I'm trying to distinguish button based on their type obviously without success since the buttonType property appears to be broken (or useless). As always thanks very much for any enlightenment you may provide!

UIButton *button = [[UIButton buttonWithType:UIButtonTypeDetailDisclosure] retain];
button.frame = frame;
NSLog(@"###################### LeftCalloutButtons - buttonWithTitle(73) - button type = %d",button.buttonType);
A: 

I encountered cases when UIButton properties (backgroundColor in my case) would have bogus value until the button is added to a view. Try querying the property once the button is on the screen.

EDIT: just saw another example of this behavior. This time it was about UISwitch.on. If I set it to YES right after alloc/init, it's not displayed as on. If I set it to YES in the viewDidLoad handler, it works as expected.

Apparently there's some lazy loading going on in the UIKit.

Seva Alekseyev
When I query a detaildisclosure button when the button is on-screen I still get 0: 2010-01-02 22:06:12.973 iParkNow![2405:207] ################ CALL OUT ACCESSORY TAPPED: control button type = 0
ennuikiller
A: 

This is broken for me too on ios4.1. My UIButtonTypeInfoLight button is always evaluating to UIButtonTypeCustom.

Heath Borders