필자는 최근 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>
사람이 임 잘못하고 무엇을 알고 있나요? 도움을 주시면 감사하겠습니다.
감사합니다 !!!