首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIcollectionview没有显示data.The、numberOfItemsInSection和cellForItemAtIndexPath方法,是不是firing.How可以在标签上显示数据?

UIcollectionview没有显示data.The、numberOfItemsInSection和cellForItemAtIndexPath方法,是不是firing.How可以在标签上显示数据?
EN

Stack Overflow用户
提问于 2014-08-11 07:21:27
回答 2查看 603关注 0票数 0
代码语言:javascript
复制
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  departureTimesArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    User *user = [departureTimesArray objectAtIndex:indexPath.row];
    UILabel *label = (UILabel*)[cell.contentView viewWithTag:100];
    if (!label)
    {
        label = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 90.0,90.0, 30.0)];
       label.textColor = [UIColor redColor];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont boldSystemFontOfSize:16];
        label.textColor = [UIColor colorWithRed:46.0/255.0 green:63.0/255.0 blue:81.0/255.0 alpha:1.0];
        label.tag = 100;

        [cell.contentView addSubview:label];
    }
    //    label.text=user.departureTime_Bus;
    label.text = [NSString stringWithFormat:@"%@",user.departureTime_Bus];

    return cell;
}

自定义委托方法

代码语言:javascript
复制
-(void)repaint:(NSMutableArray *)retrievedData
{
    if (retrievedData.count > 0)
    {
        NSLog(@"%@is the value",retrievedData);
        userObj = [retrievedData objectAtIndex:0];

        [departureTimesArray addObjectsFromArray:retrievedData];
        [mycollectionView reloadItemsAtIndexPaths:departureTimesArray];
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-11 16:05:06

如果数据源或委托方法没有触发,这通常是少数几件事情之一:

  1. 未设置集合视图的数据源或委托。
  2. 您的集合视图太小,以致于单元格无法容纳它。集合视图和表视图都只尝试创建它可以显示的单元格数。
  3. 如果您正在使用情节提要,请确保您在故事板中的视图控制器实际上是引用您希望它的文件。
票数 0
EN

Stack Overflow用户

发布于 2016-10-12 12:03:25

先查一下这个

代码语言:javascript
复制
@interface ViewController : UIViewController "<"UICollectionViewDelegate,UICollectionViewDataSource">"

第二件事是检查IBoutlet

代码语言:javascript
复制
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;

第三种是检查

代码语言:javascript
复制
self.collectionView.delegate=self;

self.collectionView.dataSource=self;

这三个步骤必须调用数据源和集合视图的委托方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25237801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档