![](/img/trans.png)
[英]NSCFConstantString objectAtIndex unrecognized selector sent to instance
[英]__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance
-(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];
聲明。 請幫助,在此先感謝:)
檢查從array
obtained
object
是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;
}
您將arr_list
存儲在data
不是從data
獲取並存儲到字符串中。
NSString *cellData = [data objectAtIndex:indexPath.row]
因此它不是字符串類型。您必須將其存儲在適當的類型中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.