2012-09-12 30 views
4

的UILabel財產我做下一個方法的的viewControllerSETFRAME的的.xib doesn't工作

-(void)setupDocsLabel:(NSMutableArray *)documents{  
    self.lDocumentos.frame = CGRectMake(self.lDocumentos.frame.origin.x, kFirstLabelYPosition+actualLabelYPos,self.lDocumentos.frame.size.width,lDocumentos.frame.size.height); 
    self.Documentos.frame = CGRectMake(self.Documentos.frame.origin.x, kFirstLabelYPosition+actualLabelYPos,self.Documentos.frame.size.width,self.Documentos.frame.size.height); 

    actualLabelYPos +=20.0; 


    for (DocInformation *doc in documents) { 
     NSString *textLabel = [doc.documentDescription stringByAppendingString:@" :"]; 
     UIFont *lblFont = lDocumentos.font; 
     CGSize sizeFont = [textLabel sizeWithFont:lblFont forWidth:120.0 lineBreakMode:NSLineBreakByTruncatingTail]; 

     UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(lDocumentos.frame.origin.x+20, kFirstLabelYPosition+actualLabelYPos,sizeFont.width,sizeFont.height)] retain]; 
     label.text = textLabel; 
     [label setFont:lblFont]; 
     [label setTextColor:lDocumentos.textColor]; 
     [label setBackgroundColor:[UIColor clearColor]]; 
     //[label setLineBreakMode:NSLineBreakByTruncatingTail]; 


     NSString *textDoc = doc.cdgoDocum; 
     UIFont *lblFontDoc = Documentos.font; 
     CGSize sizeFontDoc = [textDoc sizeWithFont:lblFontDoc]; 

     UILabel *labelDoc = [[[UILabel alloc] initWithFrame:CGRectMake(label.frame.origin.x+label.frame.size.width+20, kFirstLabelYPosition+actualLabelYPos,sizeFontDoc.width,lDocumentos.frame.size.height)] retain]; 
     labelDoc.text = textDoc; 
     [labelDoc setFont:lblFontDoc]; 
     [labelDoc setTextColor:lDocumentos.textColor]; 
     [labelDoc setBackgroundColor:[UIColor clearColor]]; 

     [self.scrollView addSubview:label]; 
     [self.scrollView addSubview:labelDoc]; 

     [label release]; 
     [labelDoc release]; 

     actualLabelYPos+=20.0; 
    } 
    //[self.view setNeedsDisplay]; 
    //[self.view setNeedsLayout]; 
} 

新標籤添加到滾動視圖很好,但self.lDocumentos(中的.xib的IBOutlet中)唐改變他的立場。

感謝您的幫助!

+0

你什麼時候調用'setupDocsLabel'方法?請記住,IBOutlet分配在'viewDidLoad'上,當您訪問'view'屬性時會延遲加載 –

+0

該方法在viewDidLoad中調用。當我檢查屬性時,這是實例化的。 我不知道還有什麼我可以嘗試。 – sheltrinec

回答

8

我解決了它,問題在於.xib已啓用文件檢查器中使用自動佈局