Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 无法在uicollectionview、uicollectionview的特定indexPath.row处设置单元格标题_Objective C_Ios_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Objective c 无法在uicollectionview、uicollectionview的特定indexPath.row处设置单元格标题

Objective c 无法在uicollectionview、uicollectionview的特定indexPath.row处设置单元格标题,objective-c,ios,uicollectionview,uicollectionviewcell,Objective C,Ios,Uicollectionview,Uicollectionviewcell,在处理UICollectionView时,我正在从nib加载一个单元格,如下所示 - (void)viewDidLoad { [super viewDidLoad]; /* Uncomment this block to use nib-based cells */ UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil]; [self.collectionView registerNib:cell

在处理UICollectionView时,我正在从nib加载一个单元格,如下所示

- (void)viewDidLoad
{
    [super viewDidLoad];
    /* Uncomment this block to use nib-based cells */
    UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];


    // Configure layout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView.contentInset    =   UIEdgeInsetsMake(10.0f, 0.0f, 10.0f, 0.0f);

    [flowLayout setItemSize:CGSizeMake(300, 200)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [self.collectionView setCollectionViewLayout:flowLayout];
}
我的nib文件如下所示

- (void)viewDidLoad
{
    [super viewDidLoad];
    /* Uncomment this block to use nib-based cells */
    UINib *cellNib = [UINib nibWithNibName:@"NibCell" bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];


    // Configure layout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView.contentInset    =   UIEdgeInsetsMake(10.0f, 0.0f, 10.0f, 0.0f);

    [flowLayout setItemSize:CGSizeMake(300, 200)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [self.collectionView setCollectionViewLayout:flowLayout];
}

顶部标签用于显示单元格数量,中间标签用于显示特定文本

在方法cellForItemAtIndexPath中,我只想将文本设置为特定行的单元格(在本例中,我是在第1行执行此操作):

运行应用程序时,应用程序出现问题。不仅是第1行的单元格的标题标签 设置为
这是第1行
,但也设置了第5行、第9行和第10行的标题标签:

如果有人知道我在中间做错了什么。请帮忙


“我的集合”包含1个部分和15行用于此部分。

单元格被重用。当您向下滚动且单元格1不可见时,集合视图将使其再次可用。只需为所有单元格设置文本,例如

titleLabel.text = [NSString stringWithFormat:@"this is row %d", indexPath.row];

有人知道这种情况吗?是的,我就是这么做的。我必须重新设置标题