gpt4 book ai didi

ios - 核心数据和 didSelectRowAtIndexPath

转载 作者:行者123 更新时间:2023-11-29 03:19:55 27 4
gpt4 key购买 nike

我正在尝试学习在我的应用程序中使用核心数据。我怎么会被困在这里 didSelectRowAtIndexPath

如果可能的话,我希望能够像以前一样使用我的 uitableview

arrayA 是一个从 plist 填充的 nsarray。我不知道如何更改此代码以使用核心数据

在我的核心数据中,我有 HovedMenu BarneDaab 和 Graviditeten,它们都具有包含字符串的 menuPunkt 属性。所以问题是我如何让这段代码与核心数据一起工作?

我认为 arrayA 必须更改 ofc,但是要更改什么?这是我从 plist 加载时使用的旧代码。 我想将其升级为核心数据

if ([arrayA[indexPath.row][@"menuPunkt"]isEqualToString:@"Barnedåb"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"BarneDaab" bundle:nil];
barneDaabMenuViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"barneDaab"];
[self.navigationController pushViewController:controller animated:YES];

}

这是我感染的:

- (NSFetchedResultsController *)fetchedResultsController {

if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
MBBAppDelegate *appDelegate = (MBBAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext* context = appDelegate.managedObjectContext;

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Hovedmenu" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"menuPunkt" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:context sectionNameKeyPath:nil
cacheName:nil];

self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;

return _fetchedResultsController;

}

最佳答案

基本上,似乎您需要做的就是用调用 FRC 来替换 arrayA[indexPath.row][@"menuPunkt"] 以获取适当的对象(就像您一样更新单元格内容)。

[[self.fetchedResultsController objectAtIndexPath:indexPath] valueForKey:@"menuPunkt"]

(你需要更改@"menuPunkt"的引用方法,因为你以前有字典,现在你有管理对象,所以语法糖不起作用)。

关于ios - 核心数据和 didSelectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21223112/

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