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>
有誰知道我在做什麼錯? 任何幫助表示讚賞!
謝謝!