配列がアイテムをコアデータからテーブルビューにロードする場所にしようとしています。ただし、一部の値は重複しています。したがって、データを取得するために使用している配列内で、配列に重複を削除してからテーブル ビューに表示するように指示しようとしています。しかし、何らかの理由で重複を削除していません。コードは次のとおりです。
更新しました
- (void)viewDidLoad
{
fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *weightEntity = [NSEntityDescription entityForName:@"Tracking" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:weightEntity];
result = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
NSMutableArray *cleaningArray= [NSMutableArray new];
NSSet *duplicatesRemover = [NSSet setWithArray:result];
[duplicatesRemover enumerateObjectsUsingBlock: ^(id obj, BOOL* stop)
{
if(![cleaningArray containsObject: obj])
{
[cleaningArray addObject: obj];
}
}];
cleanArray = [cleaningArray copy];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
mainCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (mainCell == nil) {
mainCell = [[dictionaryTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Entity *person = [cleanArray objectAtIndex:indexPath.row];
mainCell.nameLabel.text = person.date;
return mainCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%@", [cleanArray objectAtIndex:0]);
return cleanArray.count;
}
ありがとう!