2011-03-19 3 views
0

muscleName 항목을 테이블 뷰에 성공적으로로드했지만 각 exerciseName을 두 번째 테이블 뷰에로드하는 행운이 없습니다.Plist를 여러 테이블에로드하는 데 도움이 필요합니다.

내가 사용하는 방법은 다음과 같습니다

cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row] objectForKey: @"exerciseName"]; 

은 어쩌면 내가 상수를 정의 할 필요가?

enter image description here

편집 : 여기

가로드 첫 번째 테이블에있는 viewDidLoad에서 코드입니다 muscleName : 여기

if (muscleArray == nil) 
{ 
    //Read the plist file into an array (the root element is an array) 
    NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"plist"]; 
    NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path]; 
    self.muscleArray = rootLevel; 
    [rootLevel release]; 

내 현재의 서브 테이블 클래스입니다

import "SpecificExerciseTableViewController.h" 
    #import "MusclesTableViewController.h" 
    #import "CurlAppDelegate.h" 
    #import "DetailViewController.h" 

    @implementation SpecificExerciseTableViewController 
    @synthesize exerciseArray; 

    - (id)initWithStyle:(UITableViewStyle)style 
    { 
     self = [super initWithStyle:style]; 
     if (self) { 
     } 
     return self; 
    } 

    - (void)dealloc 
    { 
     [exerciseArray release]; 
     [super dealloc]; 
    } 

    - (void)didReceiveMemoryWarning 
    { 
     // Releases the view if it doesn't have a superview. 
     [super didReceiveMemoryWarning]; 

     // Release any cached data, images, etc that aren't in use. 
    } 

    #pragma mark - View lifecycle 
    - (void)viewDidLoad 
    { 
     self.navigationItem.title = @"Exercises"; 

     [super viewDidLoad]; 

     if (exerciseArray == nil) 
     { 
      //Read the plist file into an array (the root element is an array) 
      NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"plist"]; 
      NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path]; 
      self.exerciseArray = rootLevel; 
      [rootLevel release]; 
     } 

     // Uncomment the following line to preserve selection between presentations. 
     // self.clearsSelectionOnViewWillAppear = NO; 

     // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
     // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
    } 

    - (void)viewDidUnload 
    { 
     [super viewDidUnload]; 
     // Release any retained subviews of the main view. 
     // e.g. self.myOutlet = nil; 
    } 

    - (void)viewWillAppear:(BOOL)animated 
    { 
     [super viewWillAppear:animated]; 
    } 

    - (void)viewDidAppear:(BOOL)animated 
    { 
     [super viewDidAppear:animated]; 
    } 

    - (void)viewWillDisappear:(BOOL)animated 
    { 
     [super viewWillDisappear:animated]; 
    } 

    - (void)viewDidDisappear:(BOOL)animated 
    { 
     [super viewDidDisappear:animated]; 
    } 

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 

    #pragma mark - Table view data source 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return [self.exerciseArray count]; 
    } 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     NSUInteger row = [indexPath row]; 
     cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row]objectForKey:@"exerciseName"]; 

     return cell; 

    } 

    - (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath 
    { 
     return UITableViewCellAccessoryDisclosureIndicator; 
    } 

    #pragma mark - Table view delegate 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     // Navigation logic may go here. Create and push another view controller. 

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
     // ... 
     // Pass the selected object to the new view controller. 
     [self.navigationController pushViewController:detailViewController animated:YES]; 
     [detailViewController release]; 

    } 

    @end 

답변

0

코드가 더 이상 보이지 않으면 t에 액세스하는 것처럼 보입니다. 그는 exercises에서 시작하는 경우 그는 exerciseName 속성이 좋습니다. self.exerciseArrayexercises 개체를 가리키고 있습니까? 확인하는 가장 빠른 방법은 그냥 NSLog() 문에 드롭하고 당신은 당신이 당신이 무슨 생각이 있는지 확인한다 :

NSLog(@"Exercises: %@", self.exerciseArray); 
+0

내가 위의 편집에 첫 번째 테이블의있는 viewDidLoad에서 코드를 추가했다. –

+0

그리고 그 NSLog에서, 나는 (null)을 얻는다. 흠 ... –

+0

@ 파이살 : 첫 번째보기에서 행을 탭하면 루트 배열의 행 인덱스에있는 사전을 가져올 수 있습니다. 'exercises' 배열은 그 사전 안에 있습니다. '[[muscleArray objectAtIndex : row] objectForKey : @ "exercises"]'당신이하고있는 일인가요? –

관련 문제