将核心数据结果传递给 UILabel
我正在从表中选择一行。我想将该选择的结果传递给新视图上的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要新的获取结果控制器。您只需将与所选表视图行关联的托管对象传递给下一个控制器即可。您收到错误是因为您尚未执行提取,并且在任何情况下提取请求都没有
objectAtIndexPath
方法。如果您有表视图的获取结果控制器,则可以使用以下命令找到选定的对象:
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: