-(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 array
是 string
还是 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/