2011-03-18 2 views
1

data.plist를 만들고 루트 배열 (이름)을 테이블보기로로드 한 다음 각 셀을 클릭하면 해당 연습 배열을 새로운 테이블로로드합니다 테이블보기. 이 메소드를 어떻게 TableViewController에 구현합니까?Plist를 여러 테이블보기로로드하는 방법

현재 plist는 각 근육 그룹 (항목 0, 그 다음 하위 이름)에 대한 사전 항목이있는 루트 배열을 가지고 있으며 근육의 운동을위한 배열을 포함합니다. 2 뷰 서브 푸시 제 테이블

내 didSelectRowAtIndexPath 방법은 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    ExerciseTableViewController *detailViewController = [[ExerciseTableViewController alloc] initWithNibName:@"AbdominalTableViewController" bundle:nil]; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
2 테이블 뷰 컨트롤러 (이 고정 될 필요) 용

내 viewDidLoad에 방법은 다음과

- (void)viewDidLoad 

if (exerciseArray == nil) 
{ 
    NSString *path = [[NSBundle mainBundle]pathForResource:@"biceps" ofType:@"plist"]; 
    NSMutableArray *array = [[NSMutableArray alloc]initWithContentsOfFile:path]; 
    self.exerciseArray = array; 
    [array release]; 

답변

0

나는 당신이 질문하는 것을 이해한다고 가정합니다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *muscle = [muscles objectAtIndex:indexPath.row]; //'muscles' array is the first level of your plist 
    ... 
    ExerciseTableViewController *detailViewController = [[ExerciseTableViewController alloc] initWithNibName:muscle bundle:nil]; 

    detailViewController.muscle = muscle; 

    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
    ... 
} 

그리고 두 번째 컨트롤러 :

... 
    NSString *path = [[NSBundle mainBundle]pathForResource:@"biceps" ofType:@"plist"]; 
    NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
    self.exerciseArray = [plistDict objectForKey:muscle]; //'muscle' is the string you set in the previous controller 
    [plistDict release]; 
    ... 

이 도움의 희망

당신이 뭔가를 할 수 있습니다. 다음 PLIST 파일을 사용

: 파이 주석 후

편집이 PLIST를 읽기 Data.plist 당신은 할 수 있습니다 :

//Read the plist file into an array (the root element is an array) 
NSString *path = [[NSBundle mainBundle]pathForResource:@"Data" ofType:@"plist"]; 
NSArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path]; 

을 다음 두 번째 수준의 'rootLevel을'읽기 내용 :

NSDictionary *secondLevel = [rootLevel objectAtIndex:0]; 
NSString *muscle = [secondLevel valueForKey:@"name"]; //"Biceps" string 
NSArray *exercises = [secondLevel valueForKey:@"exercises"]; //[exercises objectAtIndex:0] is "Biceps Curl" string 
+0

감사합니다. GojaN. 당신은 내가 가지고있는 plist와 내가 페이지의 아래쪽에서 사용하고 싶은 plist를 볼 수있다. (이 사이트에 사진을 게시 할 수 없다.) [link] (http://forums.macrumors.com/showthread.php?t = 1120321) 그래서 내가 작성한 새로운 plist로 게시 한 코드가 작동합니까? –

+0

감사합니다. 어떤 이유로 MuscleTableViewController 클래스를 참조하고 MuslceTableViewController.h도 임포트 했는데도 ExercisesTableViewController에서 "선언되지 않은 식별자 'rootLevel'을 사용하고 있습니다.) –

+0

또한 Zip 파일에 내 코드를 첨부했습니다. 더 쉽게 볼 수있는, 감사합니다! http://www.box.net/shared/static/kf7rhhm6ji.zip –

관련 문제