-(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];
语句。请帮助,提前致谢:)
答案 0 :(得分:2)
从object
obtained
或array
检查string
array
,例如使用isKindOfClass
进行如下更改:
-(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;
}
答案 1 :(得分:0)
您将arr_list
存储在data
中,而不是从data
获取并存储到字符串中。
NSString *cellData = [data objectAtIndex:indexPath.row]
所以它不是字符串类型。您可以将它存储在适当的类型中。