gpt4 book ai didi

ios - __NSCFConstantString objectAtIndex :]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 21:54:51 25 4
gpt4 key购买 nike

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cvCell";

[self.collect registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];

CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];



NSMutableArray *data = [arr_list objectAtIndex:indexPath.section];

NSString *cellData = [data objectAtIndex:indexPath.row];

[cell.lbl setText:cellData];

return cell;


}

它正在崩溃,并产生上述错误。我编译了它,它崩溃了

 NSString *cellData = [data objectAtIndex:indexPath.row];

声明。请帮助,提前致谢:)

最佳答案

检查 object obtained from arraystring 还是 array 就像使用 isKindOfClass

这里你的对象是 NSString,你假设它是一个 NSArray

像这样修改:

 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cvCell";

[self.collect registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];

CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

id data = [arr_list objectAtIndex:indexPath.section];
NSMutableArray *arrData = nil;
if([data isKindOfClass:[NSString class]])
NSLog(@"its string");
else if([data isKindOfClass:[NSMutableArray class]])
{
arrData = (NSMutableArray *)data;
}
else
{
NSLog(@"its something else %@",data);
}

NSString *cellData = @"";
if(arrData)
cellData = [arrData objectAtIndex:indexPath.row];

[cell.lbl setText:cellData];

return cell;
}

关于ios - __NSCFConstantString objectAtIndex :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26928806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com