gpt4 book ai didi

ios - 将表的行数设置为特定实体

转载 作者:行者123 更新时间:2023-11-29 03:20:12 26 4
gpt4 key购买 nike

我正在尝试将我的 TableView Controller 的 numberOfRowsInSection: 设置为特定核心数据实体属性中的项目数量。例如,我在每个单元格的属性中的核心数据中保存了一个字符串,我希望单元格的数量与字符串相同。然后我在实体中有另一个属性,它包含每个单元格的图像。由于这两个属性,我想将单元格的数量设置为刺的数量,而不是实体中对象的数量。如果我根据实体中对象的数量来做,我将拥有两倍于我需要的单元格数量。我有一种方法可以尝试执行此操作,但该表未创建任何单元格。我的问题是当前没有使用此 numberOfRowsInSection: 创建单元格,我将如何修复此代码以使单元格出现?

这是我尝试的方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

NSManagedObjectContext *context = [self managedObjectContext];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"FeedEntity" inManagedObjectContext:context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"urlString"]];

request.sortDescriptors = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO]];
NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

// Execute the fetch.
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
if (objects == nil) {
// Handle the error.
}


id sectionInfo =
[[theFetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];

}

最佳答案

我的问题是我没有同时将两个对象保存到核心数据,而是有两种方法来保存它们,一种用于字符串,一种用于图像。我只是将它们浓缩成一种方法,而且效果很好。

关于ios - 将表的行数设置为特定实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21198471/

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