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

标签 ios objective-c iphone xcode uicollectionview

-(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/

相关文章:

iOS-deleteRowsAtIndexPaths 崩溃

android - 如何在 iOS 上注册 React Native 模块

iphone - UITableViewController 没有更新内容是我应用手动排序

javascript - iOS 偶尔会得到一个 "smeared look"

ios - 带有滤色器的 UIWebView

iPhone - 最终确定 Apple 的模糊 "VerificationController.m"

ios - 仅更改 UIImageView 的高度

iphone - 应用设计-菜单系统

iphone - iOS - 如何实现UILabel上文字的浮雕效果?

ios - 如何找到 NSMutableArray 索引