rdurand
rdurand

Reputation: 7410

JQuery Mobile in iOS project without phonegap

Before I start, please don't yell at me telling me the answer is here or there, all my researches are polluted with phonegap results, and I don't use it, so I have troubles finding the answer !

I'm currently developing a native iOS app. It's almost done, except one section, which will contain a lot of text (basically all the rules of a sport, 10 sections with 2 to 18 sub-sections and a lot of text in each). I started the implementation, using a UITableViewController to display the main sections, and selecting a cell brings me to another UITableViewController with all the sub-sections of the selected section. Then, selecting a sub-section, you're supposed to get its content. What I've started to do is use another UITableVC with TextViews in the cells, using section headers to structure the text, but that's really not convenient nor is it nice to read.

So, I want to use html pages in UIWebViews. I'm thinking of using JQueryMobile, as I've used it in the past and I think you can get nice results pretty quickly. So, I have a couple of questions :

  1. First, what do you think of the structure of this section ? (a UITableVC sending to another UITableVC, bringing up a UIWebView). How can I do something as readable as possible ? It's really the first time I have to put that much text in an app, so I'm not as sure of my design as when I develop more "standard" things. I want to do something better, but I have no idea how I can do something better..

  2. Secondly, is JQuery Mobile a good option ? And this brings the real question : how do I include JQuery Mobile in my app ? I know I can include the .js and .css directly from JQuery's servers, but my app can run offline, so where should I put the needed files ? How do I include them in the html files ?

Thanks for your help, and again, if the second question has been asked/answered, I'm sorry, but when you search for JQuery Mobile and iOS, all you get is PhoneGap questions..

Just in case :

XCode 4.5.1

iOS 5+

Storyboard

ARC

Upvotes: 0

Views: 451

Answers (1)

lqs
lqs

Reputation: 1454

Becuase UIWebView objects will cost a lot of memory, it's better to have only one UIWebView object in the native view. Don't add it for each row of UITableViewController.

You can write the web pages and include jQuery Mobile as normal and test them on Mobile Safari (by starting a server on your Mac and access it in your iOS device/emulator). After testing, add the directory in your XCode project as the blue 'folder reference'. Use the following code to load the page in UIWebView:

NSString *baseDirectory = [[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"your_directory"];
NSURL *url = [NSURL URLWithString:@"your_index.html" relativeToURL:[NSURL fileURLWithPath:baseDirectory]]
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3600];
[webView loadRequest:request];

Upvotes: 2

Related Questions