Ios 视图控制器之间的核心数据

Ios 视图控制器之间的核心数据,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我对如何将选定的objectAtIndexPath传递到详图视图控制器感到困惑。根视图控制器是运动员的表视图。选中时,我希望详细视图控制器(将被推入导航堆栈的控制器)了解刚刚选择的所有内容,例如所有属性、名称、电话等。我只是不知道要传递什么。这是我的 tableview.h //how I populate the table -(void)viewWillAppear:(BOOL)animated{ AppDelegate *appDelegate = [[UIAppl

我对如何将选定的objectAtIndexPath传递到详图视图控制器感到困惑。根视图控制器是运动员的表视图。选中时,我希望详细视图控制器(将被推入导航堆栈的控制器)了解刚刚选择的所有内容,例如所有属性、名称、电话等。我只是不知道要传递什么。这是我的

tableview.h

//how I populate the table
    -(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:@"last" 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];
    }


//how I try to send, and fail
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    NSString *segueIdentifier = [segue identifier];
    if ([segueIdentifier isEqualToString:@"setAthlete"])
    {
        UITableViewCell *cell = (UITableViewCell*) sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
        /*
        Athlete *athlete = [self.athleteArray objectAtIndexPath:indexPath];
        I cant send the array, what do I do?
    }
}

顺便说一句,我没有获取的结果视图控制器。谢谢。

运动员.h

@interface Athlete : UIViewController
{
    NSArray *arrayList;
}

@property(nonatomic, retain)NSArray *arrayList;

@end
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    NSString *segueIdentifier = [segue identifier];
    if ([segueIdentifier isEqualToString:@"setAthlete"])
    {
        UITableViewCell *cell = (UITableViewCell*) sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        Athlete *athlete = [[Athlete alloc] initWithNibName:@"Athlete" bundle:nil];
        athlete.arrayList= [self.athleteArray objectAtIndexPath:indexPath];


    }
}
合成arraylist in.m

@synthesize arrayList;
tableview.h中

@interface Athlete : UIViewController
{
    NSArray *arrayList;
}

@property(nonatomic, retain)NSArray *arrayList;

@end
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    NSString *segueIdentifier = [segue identifier];
    if ([segueIdentifier isEqualToString:@"setAthlete"])
    {
        UITableViewCell *cell = (UITableViewCell*) sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        Athlete *athlete = [[Athlete alloc] initWithNibName:@"Athlete" bundle:nil];
        athlete.arrayList= [self.athleteArray objectAtIndexPath:indexPath];


    }
}
尝试此项了解更多详细信息检查此项