2014-10-24 6 views
0

dataArray의 셀을 표시하는 collectionView가 있습니다. dataArray은 segmentControl에서 self.postsArray 또는 self.eventsArray으로 변경되고 reuseIdentifier는 셀 (사후 셀 및 이벤트 셀)을 결정합니다. 이벤트는 정상적으로 작동하지만 태그가 95 인 레이블이 포함 된 포스트 셀은 작동하지 않습니다. 내가 NSLog(@"label: %@", label); 일 때 나는 아무것도 얻지 못한다. 그래서 나는 그 문제가 뭔지 전혀 모른다.UILabel은 collectionView 셀에 표시되지 않습니다.

#pragma mark Collection View: 
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
return 1; 
} 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
return [dataArray count]; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; 

if (dataArray == self.postsArray) { 
    UILabel *label = (UILabel *)[cell viewWithTag:95]; 
    [label.text isEqualToString:@"Hello"]; 
    NSLog(@"label: %@", label); 
    return cell; 
} 

if (dataArray == self.eventsArray) { 
    PFObject *temp = [dataArray objectAtIndex:indexPath.row]; 
    UIButton *eventButton = (UIButton *) [cell viewWithTag:10]; 
    NSLog(@"Event: %@", eventButton); 
    UIButton *groupButton = (UIButton *) [cell viewWithTag:11]; 
    [eventButton setTitle:[temp objectForKey:@"Title"] forState:UIControlStateNormal]; 
    [groupButton setTitle:[temp objectForKey:@"Group_Name"] forState:UIControlStateNormal]; 

    eventButton.tag = indexPath.row; 
    groupButton.tag = indexPath.row; 
    return cell; 
} 
return cell; 
} 


#pragma mark SegmentControl: 
- (void) segmentChanged: (id) sender{ 
UISegmentedControl *seg = (UISegmentedControl *) sender; 
if (seg.selectedSegmentIndex == 0) { 
    dataArray = self.postsArray; 
    reuseIdentifier = @"postsCell"; 
    [self.collectionView reloadData]; 
} 
if (seg.selectedSegmentIndex == 1) { 
    dataArray = self.eventsArray; 
    reuseIdentifier = @"eventCell"; 
    [self.collectionView reloadData]; 
} 

}

+0

당신이 IB에서 올바르게 태그를 설정 하시겠습니까 내있는 viewDidLoad에 남아 있었다 나의 첫번째 세포를 숨어? 레이블을 기록한 직후에 셀을 기록하면 올바른 셀이 표시됩니까? 두 번째 세그먼트를 선택한 다음 첫 번째 세그먼트를 선택하면 여전히 nil이 발생합니까? – rdelmar

+0

당신이 말한 것과 같이'hidden == true'를 본 후에 셀을 기록했습니다. viewDidLoad에서'self.collectionView registerClass : [UICollectionViewCell class] forCellWithReuseIdentifier : groupReuseIdentifier '를 남겼습니다. 감사합니다 @rdelmar – Peter

답변

1

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:groupReuseIdentifier];

관련 문제