我对如何将选定的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?
}
}
我没有获取结果视图控制器顺便说一句。并谢谢。
答案 0 :(得分:0)
Athlete.h
@interface Athlete : UIViewController
{
NSArray *arrayList;
}
@property(nonatomic, retain)NSArray *arrayList;
@end
在.m
中合成arraylist@synthesize arrayList;
在 tableview.h
中-(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];
}
}
尝试此操作以获取更多详细信息,请查看此Passing Data between View Controllers