将核心数据结果传递给 UILabel

发布于 2024-11-03 01:20:44 字数 855 浏览 1 评论 0原文

我正在从表中选择一行。我想将该选择的结果传递给新视图上的 UILabel。我需要 NSFetchRequestController 子例程来执行以下操作吗?我想要一种更简单的方法将事件核心数据选择传递给非 UITableView 控制器(只是常规 UIViewController)。

下面的 objectIndexPath 处的“请求”导致了错误。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReviewController *reviewViewController = [[ReviewController alloc] init];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    Event *selectedEvent = (Event *)[request objectAtIndexPath:indexPath];
    reviewViewController.event = selectedEvent; 
    [self.navigationController pushViewController:reviewViewController animated:YES];
    [reviewViewController release];
} 

I'm selecting a row from a table. I want to pass the results of that selection to a UILabel on a new View. Do I need an NSFetchRequestController subroutine for the below? I wanted a simpler way to pass the event core data selection to a non-UITableView Controller (just a regular UIViewController).

The 'request' at objectIndexPath below is causing the error.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReviewController *reviewViewController = [[ReviewController alloc] init];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    Event *selectedEvent = (Event *)[request objectAtIndexPath:indexPath];
    reviewViewController.event = selectedEvent; 
    [self.navigationController pushViewController:reviewViewController animated:YES];
    [reviewViewController release];
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2024-11-10 01:20:45

您不需要新的获取结果控制器。您只需将与所选表视图行关联的托管对象传递给下一个控制器即可。您收到错误是因为您尚未执行提取,并且在任何情况下提取请求都没有 objectAtIndexPath 方法。

如果您有表视图的获取结果控制器,则可以使用以下命令找到选定的对象:

reviewViewController.event =[[self.fetchedResultsController fetchedObjects] objectAtIndex:index.row];

You don't need a new fetched results controller. You just pass the managed object associated with the selected tableview row to the next controller. You are getting the error because you haven't performed a fetch and in any case a fetch request does not have a objectAtIndexPath method.

If you have a fetched results controller for the tableview, you find the selected object with:

reviewViewController.event =[[self.fetchedResultsController fetchedObjects] objectAtIndex:index.row];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文