ios - [NSCFArray 长度] : unrecognized selector sent to instance

标签 ios objective-c xcode nsarray

我正在尝试用数组中的一些数据填充 TableView 。该数组已填充,但是当我运行该应用程序时出现此错误:原因:'-[__NSCFArray 长度]:无法识别的选择器已发送到实例

我搜索过类似的问题,但没有一个适合我。我没有使用 lenght 函数,我的应用程序崩溃了:cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row];

quizViewController.m

- (void)passDataForward
{
    ScoreViewController *secondViewController = [[UIStoryboard storyboardWithName:@"Storyboard" bundle:[NSBundle mainBundle]]instantiateViewControllerWithIdentifier:@"score"];

    secondViewController.data =self.scoreLabel.text;
    secondViewController.delegate = self;

    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    [highScores insertObject:self.scoreLabel.text atIndex:highScores.count];

    NSData *currentDate =[NSDate date];
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"dd.MM.YYYY                        HH:mm:ss"];
    NSString *dateString =[dateFormatter stringFromDate:currentDate];

    [data insertObject:dateString atIndex:data.count];



    NSMutableArray *scorearray = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"high_scoresarray"]];

     NSMutableArray *dataArray = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"data_score"]];

    [scorearray addObject:highScores];
    [dataArray addObject:data];

    [[NSUserDefaults standardUserDefaults] setObject:scorearray forKey:@"high_scoresarray"];
    [[NSUserDefaults standardUserDefaults] setObject:dataArray forKey:@"data_score"];


    secondViewController.test=[NSMutableArray arrayWithArray: scorearray];
    secondViewController.currentDate=[NSMutableArray arrayWithArray: dataArray];

    [self presentViewController:secondViewController animated:YES completion:^(void)
     {

     }];
}

ScoreViewController.m

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row];
   cell.detailTextLabel.text=[self.test objectAtIndex:indexPath.row];

    return cell;
}

最佳答案

错误意味着这一行:

[self.currentDate objectAtIndex:indexPath.row]

返回一个数组而不是一个 NSString。这意味着

self.currentDate

包含 NSArray 对象而不是 NSString 对象。

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

相关文章:

objective-c - magicalrecord 删除非导入数据

ios - xcode 5 ld : 11 duplicate symbols for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ios - Objective-C继承

arrays - 永久数据并为 Segue 做准备

ios - 如何集成AdMob作为iAds的备份?

ios - SpriteKit捏变焦相机

iOS 应用程序在安装和中断安装期间显示错误警报

ios - 在 Swift 中使用 conds_t 的 NSNumber?

iphone - 从 Objective-C 使用 Url 调用谷歌地图

ios - Xcode 无法单击问题导航器中的错误