I've been doing a navigation stack that populates a table with a plist. However I can seem to pass the "Name" information to my third table when I click the "City" because nothing displays. I do get a new table to popup but it should populate with "Grand Canyon" but it doesn't. I have successfully passed from "Destination" to "City" but not to "Name". I think the problem is where the beginning loop which does not recognizing the key to write the "Name".
Plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Destination</key>
<string>Arizona</string>
<key>Tours</key>
<array>
<dict>
<key>City</key>
<string>Phoenix</string>
<key>Options</key>
<array>
<dict>
<key>Name</key>
<string>Grand Canyon</string>
</dict>
</array>
</dict>
</array>
</dict>
<dict>
<key>Destination</key>
<string>California</string>
<key>Tours</key>
<array>
<dict>
<key>City</key>
<string>San Diego</string>
</dict>
<dict>
<key>City</key>
<string>Calexico</string>
</dict>
</array>
</dict>
</array>
</plist>
Code:
#import "OptionsViewController.h"
@interface OptionsViewController ()
@property NSArray *options;
@end
@implementation OptionsViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Available Tours";
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
-(void)setToursAvailable:(NSString *)toursAvailable{
if (_toursAvailable != toursAvailable) {
_toursAvailable = toursAvailable;
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Destination" ofType:@"plist"];
NSArray *tours =[NSArray arrayWithContentsOfFile:filePath];
for (int i = 0; i < [tours count]; i++) {
NSDictionary *tourDictionary = [tours objectAtIndex:i];
NSString *tempTour = [tourDictionary objectForKey:@"City"];
if ([tempTour isEqualToString:_toursAvailable]) {
self.options = [tourDictionary objectForKey:@"Options"];
}
}
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.options count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//Fetch Options
NSDictionary *opt = [self.options objectAtIndex:[indexPath row]];
// Configure the cell...
[cell.textLabel setText:[opt objectForKey:@"Name"]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}