gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:18:25 27 4
gpt4 key购买 nike

我正在尝试用数组中的一些数据填充 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com