2013-08-04 4 views
-1

선택한 objectAtIndexPath를 상세보기 컨트롤러로 전달하는 방법에 대해 혼란스러워합니다. 루트보기 컨트롤러는 운동 선수의 테이블보기입니다. 내가 선택하면, 디테일 뷰 컨트롤러 (네비게이션 스택으로 푸시 될 컨트롤러)가 방금 선택한 내용에 대해 모두 알기를 원합니다. 모든 속성, 이름, 전화, 등등. 나는 그냥 통과 해야하는지 혼란스러워. 여기에 내가 가진 것이있다.보기 컨트롤러 간의 핵심 데이터

tableview.h I가 도중에 페치 결과보기 컨트롤러 해달라고

//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? 
    } 
} 

. 그리고 감사합니다. 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]; 


    } 
} 

으로하는 .m

@synthesize arrayList; 

답변

0

에서 Athlete.h가

@interface Athlete : UIViewController 
{ 
    NSArray *arrayList; 
} 

@property(nonatomic, retain)NSArray *arrayList; 

@end 

합성의 ArrayList를이 Passing Data between View Controllers을 확인보다 상세히 이것을 시도

관련 문제