简体   繁体   English

[NSCFArray length]:发送到实例的无法识别的选择器

[英][NSCFArray length]: unrecognized selector sent to instance

I'm trying to fill a table view with some data from an array . 我试图用来自数组的一些数据填充表视图。 The array is populated but when i run the app i get this error : reason: '-[__NSCFArray length]: unrecognized selector sent to instance 数组已填充,但是当我运行应用程序时出现此错误:原因:'-[__ NSCFArray length]:无法识别的选择器已发送到实例

I searched for similar questions , but no one was the right for me. 我搜索了类似的问题,但没有人适合我。 I don't use the lenght function and my app is crashing on : cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row]; 我不使用长度函数,我的应用程序崩溃在:cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row];

quizViewController.m 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 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;
}

The error means that this line: 该错误表示该行:

[self.currentDate objectAtIndex:indexPath.row]

returns an Array instead of an NSString. 返回一个数组而不是一个NSString。 Which means that 意思就是

self.currentDate

contains NSArray objects and not NSString objects. 包含NSArray对象而不是NSString对象。

Aris is right. 阿里斯是对的。 self.currentDate returns an NSArray . self.currentDate返回一个NSArray And that is caused by: 这是由于:

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

Where you are adding one array as the only item to the array scorearray and dataArray respectively. 在其中将一个数组作为唯一项分别添加到数组scorearraydataArray You do not add a bunch of strings, which I assume are stored within highScores and data . 您无需添加一堆字符串,我认为这些字符串存储在highScoresdata Replace it with 替换为

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

That should add the contents of highScores and data to scorearray and dataarray . 那应该将highScoresdata的内容添加到scorearraydataarray

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [__NSCFArray 长度]:无法识别的选择器发送到实例 - [__NSCFArray length]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[__ NSCFArray length]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance [NSCFArray行]:无法识别的选择器已发送到实例0x3953a20 - [NSCFArray row]: unrecognized selector sent to instance 0x3953a20 NSDictionary长度:无法识别的选择器已发送到实例 - NSDictionary length :unrecognized selector sent to instance [__NSCFNumber length]:无法识别的选择器发送到实例UITableView - [__NSCFNumber length]: unrecognized selector sent to instance UITableView [__NSArrayI length]:无法识别的选择器已发送到实例 - [__NSArrayI length]: unrecognized selector sent to instance -[NSNull 长度]:无法识别的选择器发送到实例 - -[NSNull length]: unrecognized selector sent to instance NSInvalidArgumentException-[NSNull长度]:无法识别的选择器已发送到实例 - NSInvalidArgumentException -[NSNull length]: unrecognized selector sent to instance UILocalizedIndexedCollat​​ion-[__ NSCFNumber length]:无法识别的选择器已发送到实例 - UILocalizedIndexedCollation -[__NSCFNumber length]: unrecognized selector sent to instance 解析json并获取异常,原因:'-[__ NSCFArray objectForKey:]:无法识别的选择器已发送到实例0x7b1c7630 - parsing json and getting exception, reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x7b1c7630
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM