I am having a difficult time unzipping a file containing 3000+ files and then using those files to populate the detailed view of a searchable UITableView.
I have a searchable UITableView that contains information on 3000+ English nouns. If you select a cell from within the table, you’ll be taken to a UIWebView that uses html files to populate additional information about the selected noun. For example, if I were to select the cell containing the word “water,” it would use a file called “water.html” for the detailed UIWebView. If I copy the water.html file to my project (to where it shows up in the left sidebar in xcode), it works exactly how I want it to.
Screenshots
- https://i.stack.imgur.com/aJxee.png (search view)
- https://i.stack.imgur.com/EguBE.png (detailed view)
However, if I add 3000+ html files to my project, xcode slows to the point where I can't get anything done. I’m open to alternative suggestions, but one of the solutions I found was to include a .zip file containing those files and find a way to unzip it only when the app is run for the first time or after an update. I also read somewhere that I could have the files copied over during the build phase, but I'm not quite sure what that would entail. I have already made all of the html files using a macro in Excel, so I would prefer to avoid any solutions that involves changing that aspect.
I’ve made a great deal of effort to figure out a solution via Google, but I just haven’t been able to get anything I try to work properly. Any help is greatly appreciated. I have no previous experience in objective-c prior to this, so I do use a lot of borrowed code from online tutorials. It's probably not the most efficient, but it's what I've got in place.
I’ve already looked at previous Stack Overflow questions that discuss unzipping files. I have read through dozens of answers with no success. I have tried SSZipArchive, and I already have the files for this in my project. If possible, I would prefer to use this, but I don’t know where or how to implement it.
Answers to questions like this have been very helpful, but I haven’t found one specific enough to my needs to figure it out how to implement it yet. How to unzip a .zip file on iOS?
The parts I’m struggling to figure out are:
- How do I execute the unzip process? (Where do I place the code?)
- What directory should I unzip the file to and how? (I’m not familiar with default directory names.)
- How do I change the detailView code to access the directory the html files were unzipped to?
I use an NSArray to populate the UITableView like this:
Item *item1 = [Item new];
item1.nounSingular = @"aardvark";
item1.nounPlural = @"aardvarks";
item1.nounType = @"規則";
Item *item2 = [Item new];
item2.nounSingular = @"ability";
item2.nounPlural = @"abilities";
item2.nounType = @"規則";
Item *item3 = [Item new];
item3.nounSingular = @"abroad";
item3.nounPlural = @"なし";
item3.nounType = @"不可算";
Item *item4 = [Item new];
item4.nounSingular = @"absence";
item4.nounPlural = @"absences";
item4.nounType = @"規則";
Item *item5 = [Item new];
item5.nounSingular = @"abstract";
item5.nounPlural = @"abstracts";
item5.nounType = @"規則";
Item *item6 = [Item new];
item6.nounSingular = @"abuse";
item6.nounPlural = @"abuses";
item6.nounType = @"規則";
Item *item7 = [Item new];
item7.nounSingular = @"accelerator";
item7.nounPlural = @"accelerators";
item7.nounType = @"規則";
Item *item8 = [Item new];
item8.nounSingular = @"accent";
item8.nounPlural = @"accents";
item8.nounType = @"規則";
Item *item9 = [Item new];
item9.nounSingular = @"water";
item9.nounPlural = @"なし";
item9.nounType = @"不可算";
items = [NSArray arrayWithObjects:item1, item2, item3, item4, item5, item6, item7, item8, item9, nil];
Here’s the segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showItemDetail"]) {
NSIndexPath *indexPath = nil;
Item *item = nil;
if (self.searchDisplayController.active) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
item = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.tableView indexPathForSelectedRow];
item = [items objectAtIndex:indexPath.row];
}
ItemDetailViewController *destViewController = segue.destinationViewController;
destViewController.item = item;
}
}
Lastly, I refer to the nounSingular identifier I used in the "item" array to load the html file like this:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:self.item.nounSingular ofType:@"html"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
Whenever possible, please be detailed with explanations if you can. It would really help me out a lot, and I best learn from example. I have a web design background, and I am only about a month or so into building my first app. This is the last issue I need to address before submitting my app for release, so I really appreciate any help you can provide!