I've created a split view style app that uses a plist by by modifying the example found here: https://github.com/jllust/UIStoryboardExamples/tree/master/UIStoryBoardDrillDown
When an Item in the UITableview is selected, if an address is present it loads a local html file, if an array is present it loops back the UITable and populates it with the child array. Everything works great up till the loading of the HTML. Only the "Root Level" seems to load html, even though logging shows that child levels are accessing the data in the plist correctly. It's almost as if the web view can't find the local html in the bundle. Below is some of the code that controls the Tableview:
#import "tdlwMasterViewController.h"
#import "tdlwDetailViewController.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@interface tdlwMasterViewController () {
NSMutableArray *_objects;
}
@end
@implementation tdlwMasterViewController
- (void)awakeFromNib
{
self.clearsSelectionOnViewWillAppear = NO;
//self.preferredContentSize = CGSizeMake(320.0, 600.0);
[super awakeFromNib];
self.tableView.backgroundColor = UIColorFromRGB(0x353535);
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:@"ItemList" ofType:@"plist"];
NSDictionary* thelist = [NSDictionary dictionaryWithContentsOfFile:path];
self.items = [thelist objectForKey:@"items"];
self.navigationItem.title = [thelist objectForKey:@"name"];
UIImage *img = [UIImage imageNamed:@"logo.png"];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:img];
self.detailViewController = (tdlwDetailViewController *)
[[self.splitViewController.viewControllers lastObject]
topViewController];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UIStoryBoard Delegate
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UITableViewCell* cell = (UITableViewCell*)sender;
NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
NSDictionary* rowData = [self.items objectAtIndex:indexPath.row];
if ([segue.identifier isEqualToString:@"loopbackSegue"]) {
tdlwMasterViewController* drillVC = (tdlwMasterViewController*)segue.destinationViewController;
drillVC.items = [rowData objectForKey:@"items"];
drillVC.title = [rowData objectForKey:@"name"];
}
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* loopbackCell = @"loopbackCell";
static NSString* detailCell = @"detailCell";
UITableViewCell* cell;
NSDictionary* rowData = [self.items objectAtIndex:indexPath.row];
if ([rowData objectForKey:@"items"]) {
cell = [tableView dequeueReusableCellWithIdentifier:loopbackCell];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:detailCell];
}
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = UIColorFromRGB(0x173953);
cell.backgroundColor = UIColorFromRGB(0x353535);
cell.selectedBackgroundView = customColorView;
cell.textLabel.text = [rowData objectForKey:@"name"];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary* rowData = [self.items objectAtIndex:indexPath.row];
if ([rowData objectForKey:@"address"]) {
NSLog([rowData objectForKey:@"address"]);
NSLog([rowData objectForKey:@"name"]);
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *urlString = [rowData objectForKey:@"address"];
NSURL *homeIndexUrl = [mainBundle URLForResource:urlString withExtension:@"html" ];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:homeIndexUrl];
self.detailViewController.webView.scalesPageToFit = NO;
self.detailViewController.detailTitle.title = [rowData objectForKey:@"name"];
[self.detailViewController.webView loadRequest:urlReq];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MASTERROWSELECTED"
object:nil];
}else {
NSLog(@"wtf");
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
The Plist is nothing special but here it is:
<?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">
<dict>
<key>name</key>
<string>Table Of Contents</string>
<key>items</key>
<array>
<dict>
<key>address</key>
<string>welcome</string>
<key>name</key>
<string>Welcome</string>
</dict>
<dict>
<key>address</key>
<string>cover</string>
<key>name</key>
<string>Cover Letter</string>
</dict>
<dict>
<key>name</key>
<string>Qualifications</string>
<key>items</key>
<array>
<dict>
<key>name</key>
<string>Company Profile</string>
<key>address</key>
<string>profile</string>
</dict>
<dict>
<key>address</key>
<string>ea</string>
<key>name</key>
<string>Experience & Approach</string>
</dict>
<dict>
<key>name</key>
<string>Relevant Work</string>
<key>items</key>
<array>
<dict>
<key>address</key>
<string>client1</string>
<key>name</key>
<string>client1</string>
</dict>
<dict>
<key>address</key>
<string>client2</string>
<key>name</key>
<string>client2</string>
</dict>
<dict>
<key>address</key>
<string>client3</string>
<key>name</key>
<string>client3</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>References</string>
<key>items</key>
<array>
<dict>
<key>name</key>
<string>client1</string>
<key>address</key>
<string>client1-letter</string>
</dict>
<dict>
<key>address</key>
<string>client2-letter</string>
<key>name</key>
<string>client2</string>
</dict>
<dict>
<key>address</key>
<string>client3-letter</string>
<key>name</key>
<string>client3</string>
</dict>
</array>
</dict>
<dict>
<key>address</key>
<string>tc</string>
<key>name</key>
<string>Terms & Conditions</string>
</dict>
</array>
</dict>
<dict>
<key>address</key>
<string>project</string>
<key>name</key>
<string>Project Management</string>
</dict>
<dict>
<key>address</key>
<string>partners</string>
<key>name</key>
<string>Partners and/or Subvendors</string>
</dict>
<dict>
<key>name</key>
<string>Timeline/Creative Brief</string>
<key>address</key>
<string>timeline</string>
</dict>
<dict>
<key>name</key>
<string>Scope of Work & Budget</string>
<key>address</key>
<string>scope</string>
</dict>
</array>
</dict>
</plist>
If any more of the code is needed, let me know, but I'm at a loss and I really need to find an answer to this.
For anyone that stumbles across this, I solved the problem by assigning the detailViewController back to the created drillVC. The last line in the if statement solved it.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UITableViewCell* cell = (UITableViewCell*)sender;
self.myView = self.detailViewController.webView;
NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
NSDictionary* rowData = [self.items objectAtIndex:indexPath.row];
if ([segue.identifier isEqualToString:@"loopbackSegue"]) {
tdlwMasterViewController* drillVC = (tdlwMasterViewController*)segue.destinationViewController;
drillVC.items = [rowData objectForKey:@"items"];
drillVC.title = [rowData objectForKey:@"name"];
drillVC.detailViewController = self.detailViewController;
}
}