0
我最近下载了Jeff LaMarche的分段表格视图,并试图实现一个细节视图。问题是我不知道把什么放在我的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>
有谁知道我在做什么错? 任何帮助表示赞赏!
谢谢!