Reputation: 1
Ive recently downloaded Jeff LaMarche`s sectioned table view and Im trying to implement a detail view. Problem is I dont know what to put on my didSelectRow and on viewDidLoad from detailView.m. Im using a plist for this.
This is how my table view is configured: Code:
//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"];
my plist is like this: Code:
<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>
Does anyone know what Im doing wrong? any help is appreciated!
Thanks!!!
Upvotes: 0
Views: 1205
Reputation: 57169
You will need a way of passing the details to your Details controller. A couple of options is using a property or a custom initializer.
//Detail.h
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle details:(NSString*)details;
//And/or
@property(copy) NSString *details;
Original Code
//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];
Edit
You may have other issues and one may be that you are trying to get objectForKey:
using @"Title" and that is incorrect if you have not drilled into the dates yet. Your PLIST is a dictionary of arrays of dictionaries. Here is an example of accessing a value from your array.
NSArray *values = [dictionary objectForKey:@"3 Jan"];
NSDictionary *anyValue = [values lastObject];
NSString *title = [anyValue objectForKey:@"Title"];
NSString *description = [anyValue objectForKey:@"description"];
Upvotes: 1