Apple iPhone SDK 3.0: risolto baco su UIButton buttonWithType

Come indicato nel post Apple iPhone SDK 3.0: prime incompatibilità le SDK 3.0 di Apple mostrano comportamenti differenti rispetto alla release 2.2.1. Il supporto di assistenza per gli sviluppatori mi ha fornito la risposta, e quindi la soluzione al problema. La risposta del supporto tecnico è stata che [UIButton buttonWithType:] già chiama – al suo interno – la initWithFrame. Ne deriva che, sempre secondo il supporto tecnico, scrivendo:

1
UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] initWithFrame:CGRectMake(0, 0, 100, 40)];

Si invoca la initWithFrame due volte, causando la perdita del testo label. In pratica basta sostituire il codice sopra con:

1
2
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame     = CGRectMake(0, 0, 100, 40);

La risposta originale:

1
2
3
+[UIButton buttonWithType:] already calls initWithFrame: for you. Calling it twice erases internal information that causes the problem you see with the disappearing text. Code changes in 3.0 revealed the bug. In your code, just say:
UIButton * restart_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
restart_button.frame = CGRectMake(40,430,100,40);

Non ci sono commenti per questo Post

Lascia un commento

TAG XHTML PERMESSI: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERIMENTO CODICE:
<pre></pre> // blocco generico
                   <code></code> // blocco generico
                   [cc_actionscript][/cc_actionscript] // Actionscript
                   [cc_actionscript3][/cc_actionscript3] // Actionscript 3
                   [cc_css][/cc_css] // CSS Style Sheet
                   [cc_html][/cc_html] // HTML
                   [cc_js][/cc_js] // Javascript
                   [cc_objc][/cc_objc] // Objective-C
                   [cc_php][/cc_objc] // PHP
                   [cc_sql][/cc_sql] // SQL