-1

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

表格视图.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?
    }
}

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

4

1 回答 1

0

运动员.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];


    }
}

试试这个以获得更多细节检查这个在视图控制器之间传递数据

于 2013-08-05T05:55:25.447 回答