2014-02-10 6 views
0

나는 사용자 정의보기를 생성하고 TT2TimeViewController의 XIB에서는 UICollectionViewCell컨트롤러는 라벨의 텍스트를 업데이트하지 않습니다

-(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
    UICollectionViewCell* newcell;// = [[UICollectionViewCell alloc] init]; 

    newcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hi" forIndexPath:indexPath]; 

    TT2TimeViewController* controller = [[TT2TimeViewController alloc] init]; 

    NSString* city = [cities objectAtIndex:indexPath.row]; 
    controller.city = city; 
    UIView* view = [[[NSBundle mainBundle] loadNibNamed:@"TT2TimeViewController" 
                owner:controller 
               options:nil] objectAtIndex:0]; 

    [newcell.contentView addSubview:view]; 
    return newcell; 
} 

의있는 contentView에 추가하려면 다음 코드를 사용, 내가 배치 가지고 UILabel을 중앙에두고 컨트롤러가 레이블 텍스트를 city 변수 값으로 업데이트하려고합니다.

그러나 어떤 이유로 인해 레이블이 예상대로 업데이트되지 않습니다. 나는 IBOutlet가 생성되고 유효하다는 것을 두 번 점검하고 확인했습니다.

#import "TT2TimeViewController.h" 

@implementation TT2TimeViewController 


-(void) viewDidLoad { 
    [self.lblCity setText:[self city]]; 
} 


-(void)viewDidAppear:(BOOL)animated { 
    [self.lblCity setText:[self city]]; 
} 

어느 함수가 호출 :

enter image description here

컨트롤러 클래스 TT2TimeViewController의 코드입니다.

enter image description here

그래서 제 질문은 다음과 같습니다 : I 함수 collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath의 구현에 아무것도 잘못 했

또 하나 개의 화면은 파일 소유자가 설정되는 방법을 보여 촬영?

+0

awakeFromNib을 사용해 보셨습니까? – santhu

+0

@santhu 시도했지만 작동하지 않았다 –

+0

self.lblCity가 NULL이 아닌지 확인 했습니까? 귀하의 IB 스크린 샷은 그것이 뭔가에 연결되어 있지만 그것이 올바른 클래스 인스턴스에 연결되어 있는지를 보여줍니다. awakeFromNib에서 중단 점이 발생합니까? 그렇다면 모든 IB 연결이 유효해야하므로이 중단 점에서 ivar이 NULL이면 제대로 연결되지 않습니다. – Mark

답변

0

나는 해결책을 발견 : 내가 지금처럼 XIB 파일의 뷰 객체에 컨트롤러의 '보기'변수를 연결해야합니다

enter image description here

그런 다음 작동하기 시작합니다.

(이상한 것 : viewDidAppear라고 부름)

관련 문제