[英][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. 在其中将一个数组作为唯一项分别添加到数组scorearray
和dataArray
。 You do not add a bunch of strings, which I assume are stored within highScores
and data
. 您无需添加一堆字符串,我认为这些字符串存储在highScores
和data
。 Replace it with 替换为
[scorearray addObjectsFromArray:highScores];
[dataArray addObjectsFromArray:data];
That should add the contents of highScores
and data
to scorearray
and dataarray
. 那应该将highScores
和data
的内容添加到scorearray
和dataarray
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.