Apple iPhone SDK 3.0: risolto baco su UIButton buttonWithType

venerdì 12 giugno, 2009

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:

Objective-C:
  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:

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

La risposta originale:

CODE:
  1. +[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:
  2. UIButton * restart_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  3. restart_button.frame = CGRectMake(40,430,100,40);

Post correlati

Questo articolo ti è stato utile?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

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
[as][/as]           // Actionscript
[css][/css]         // CSS Style Sheet
[html][/html]       // HTML
[js][/js]           // Javascript
[objc][/objc]       // Objective-C
[php][/php]         // PHP
[sql][/sql]         // SQL