【发布时间】:2016-04-21 01:50:49
【问题描述】:
在我的应用程序中,我正在显示一个日历,并且我正在使用一个集合视图来显示一周中各天的标签。出于某种原因,当我运行应用程序时,所有标签仍显示默认的“标签”。我看了一个类似的问题,但没有帮助。有什么建议么?这是 UICollectionViewCell 的代码:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CalendarTitleCellIdentifier forIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:1];
label = [[UILabel alloc] init];
CGSize size = [self collectionView:collectionView layout:collectionView.collectionViewLayout sizeForItemAtIndexPath:indexPath];
label.frame = CGRectMake(0, 0, size.width, size.height);
NSString *title = [[NSString alloc] initWithFormat:@"%@",self.weektitles[indexPath.row]];
label.text = title;
NSLog(@"%@", label.text);
return cell;
}
仅供参考,我在情节提要中有一个实际标签(在集合视图单元格中)。
【问题讨论】:
-
试试 UILabel *label = (UILabel *)[cell. contentView viewWithTag:1];
标签: ios objective-c uicollectionview uilabel