2010-03-28 11 views
8

Posso accedere e mostrare self.view e vedere il frame nel log ma quando provo ad accedere a self.view.frame ottengo null. Di seguito è riportato l'output del registro diObjective-C Posso accedere a self.view ma non self.view.frame

NSLog(@"Show self.view:%@",self.view); 
NSLog(@"Show self.view.frame:%@",self.view.frame); 

-

2010-03-28 11:08:43.373 vivmed_CD_Tab[20356:207] Show self.view:<UITableView: 0x4001600; frame = (0 0; 320 583); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x3b21270>> 
2010-03-28 11:08:43.373 vivmed_CD_Tab[20356:207] Show self.view.frame:(null) 

Qualcuno può spiegare il motivo per cui è self.view.framenull ma self.view mostra un frame? Il mio obiettivo è modificare le dimensioni del fotogramma.

Cheers, sovvenzione

risposta

19

Un problema nel codice che hai postato è che si sta stampando la cornice (un CGRect) come un oggetto, che non funziona. Prova:

NSLog(@"Show self.view.frame: %u", self.view.frame); // as a pointer 

NSLog(@"Show self.view.frame: %@", NSStringFromCGRect(self.view.frame)); // as a string 
+4

Proprio così! I primi due campi di CGRect sarebbero zero, quindi il runtime Obj-C lo interpreta come un oggetto con un puntatore di classe null. Se il frame avesse un'origine diversa, avresti avuto un arresto anomalo. – codewarrior

Problemi correlati