我试图用来自数组的一些数据填充表格视图。数组已填充,但是当我运行应用程序时出现此错误:原因:'-[__ NSCFArray length]:无法识别的选择器已发送到实例
我搜索了类似的问题,但没有人适合我。我不使用长度函数,我的应用程序崩溃在: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
返回一个NSArray
。这是由于:
[scorearray addObject:highScores];
[dataArray addObject:data];
在其中将一个数组作为唯一项分别添加到数组
scorearray
和dataArray
的位置。您不会添加一堆字符串,我认为这些字符串存储在highScores
和data
中。替换为
[scorearray addObjectsFromArray:highScores];
[dataArray addObjectsFromArray:data];
那应该将
highScores
和data
的内容添加到scorearray
和dataarray
。关于ios - [NSCFArray length]:发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27380633/