2011-03-29 5 views
0

필자는 최근 Jeff LaMarche의 섹션 테이블보기와 Im을 상세보기 구현을 위해 다운로드했습니다. 문제는 내 didSelectRow 및 detailView.m에서 viewDidLoad에 무엇을 넣을 지 모른다는 것입니다. 나는 이것을 위해 plist를 사용한다. 코드 :구분 된 테이블보기에서 상세보기로 데이터를 전달하는 방법은 무엇입니까?

이 내 테이블보기를 구성하는 방법입니다

//SectionsViewController.h 

    NSDictionary *allNames; 
    NSMutableDictionary *names; 
    NSMutableArray  *keys; 

//SectionsViewController.m 
- (void)viewDidLoad { 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]; 
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 
    self.allNames = dict; [dict release]; } 

//on cellForRowAtIndexPath: 

     NSInteger section = [indexPath section]; 
    NSInteger row = [indexPath row]; 

    NSString *key = [keys objectAtIndex:section]; 
    NSArray *nameSection = [names objectForKey:key]; 

    NSDictionary *dictionary = [nameSection objectAtIndex:row]; 

     cell.textLabel.text = [dictionary objectForKey:@"Title"] ; 

     return cell; 

//on didSelectRowAtIndexPath 

     NSString *selectedItem =[[nameSection objectAtIndex:row] objectForKey:@"Title"]; 

     Detail *dvController = [[Detail alloc] initWithNibName:@"Detail" bundle:[NSBundle mainBundle]]; 
     [self.navigationController pushViewController:dvController animated:YES]; 

    dvController.selectedItem = selectedItem; 

    [dvController release]; 
    dvController = nil; 
    NSLog(@"teste1"); 


//Detail.m 

NSDictionary *details = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]]; 

details = [details objectForKey:self.selectedItem]; 

titleLabel.text = [selectedItem objectForKey:@"Title"]; 
descriptionLabel.text = [selectedItem objectForKey:@"description"]; 

내 PLIST이 같다 : 코드 :

<dict> 
    <key>3 jan</key> 
    <array> 
     <dict> 
      <key>Title</key> 
      <string>asdf</string> 
      <key>description</key> 
      <string>asdqqq</string> 
     </dict> 
    </array> 
    <key>4 Jan</key> 
    <array> 
     <dict> 
      <key>Title</key> 
      <string>asddww</string> 
      <key>description</key> 
      <string>asdd</string> 
     </dict> 
    </array> 
</dict> 
</plist> 

사람이 임 잘못하고 무엇을 알고 있나요? 도움을 주시면 감사하겠습니다.

감사합니다 !!!

답변

1

세부 정보 컨트롤러로 세부 정보를 전달하는 방법이 필요합니다. 몇 가지 옵션은 속성이나 사용자 정의 이니셜 라이저를 사용합니다.

//Detail.h 
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle details:(NSString*)details; 
    //And/or 
@property(copy) NSString *details; 

원본 코드

//on didSelectRowAtIndexPath 
NSString *selectedItem =[[nameSection objectAtIndex:row] objectForKey:@"Title"]; 
Detail *dvController = [[Detail alloc] initWithNibName:@"Detail" bundle:[NSBundle mainBundle]]; 
dvController.details = selectedItem; 
[self.navigationController pushViewController:dvController animated:YES]; 

편집

당신은 다른 문제가있을 수 있습니다 하나는 @ "제목"을 사용하여 objectForKey:을 얻어내는 것이 될 수 있으며 경우에 그 잘못 아직 날짜를 뚫지 못했다. PLIST는 사전 배열 사전입니다. 다음은 배열에서 값에 액세스하는 예제입니다.

NSArray *values = [dictionary objectForKey:@"3 Jan"]; 
NSDictionary *anyValue = [values lastObject]; 
NSString *title = [anyValue objectForKey:@"Title"]; 
NSString *description = [anyValue objectForKey:@"description"]; 
관련 문제