UILabel不会出现在collectionView Cell中

时间:2014-10-24 21:17:02

标签: objective-c xcode uilabel uicollectionview

我有一个collectionView,它将显示dataArray中的单元格。 dataArray从segmentControl更改为self.postsArrayself.eventsArray以及reuseIdentifier以确定单元格(后单元格和事件单元格)。事件工作正常,但Post Cell(包含标签为95的标签)不起作用。当我NSLog(@"label: %@", label);我没有。所以我不知道问题是什么。

#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];
}

}

1 个答案:

答案 0 :(得分:1)

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:groupReuseIdentifier];留在我的viewDidLoad中并隐藏了我的第一个单元格