1
我的第一个视图控制器AllAthletes
是我所有核心数据实体的可用视图。它显示实体“运动员”,它的属性在字幕样式表单元格中,比如名字等。当你点击一个视图单元格时,我希望这个视图控制器传递被选中的实体的信息, m不确定如何将此信息(indexpath的managedobject,entity,properties等)传递给详细视图控制器。有人能指点我正确的方向吗?在视图控制器之间传递数据segue
allathletes.m
-(void)viewWillAppear:(BOOL)animated{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
_managedObjectContext = [appDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *athlete = [NSEntityDescription entityForName:@"Athlete" inManagedObjectContext:_managedObjectContext];
[request setEntity:athlete];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"first" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil){
//handle error
}
[self setAthleteArray:mutableFetchResults];
[self.tableView reloadData];
}
//this is what I have so far
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"setAthlete"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
AthleteDetail *destViewController = segue.destinationViewController;
}
}
//i was also thinking something like this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController* detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
NSMutableString *object = thisArray[indexPath.row];
detailViewController.passedData = object;
[self.navigationController pushViewController:detailViewController animated:YES];
}
,它会使你得到第二控制器AthleteDetail。感谢您的时间。
那么,你需要使用'performSegueWithIdentifier:sender:'。您现在正在手动推送。 – Desdenova
目前尚不清楚你的具体问题是什么。如何做到这一点在“用于iOS的表格视图编程指南”的“在表格视图中浏览数据层次结构”一节中进行了说明。阅读它,如果你仍然不明白,请提出一个更具体的问题。 – rdelmar
@rdelmar更好吗? –