Display wordpress post from JSON in iOS

Background: my app is an extension to a wordpress blog. It downloads a json containing the blog articles, parses them into individual articles (title, id, thumbnail, content) then displays them in a tableView. This part all works and looks nice.

Problem: Im looking into a good looking way to present the articles when the user taps one from the tableView. I would like it too look something like TUAW’s or BGR’s apps but I’m stuck -_- I would also like to keep the article formatting as intact as possible.

Read More

Libraries in use: SBJSON, ASIHTTPRequest, SDWebImage

Any advice

- (void)loadMyArticleData
{
    //create the beginning of the html string
    NSMutableString *html = [NSMutableString stringWithString: @"<html><head><title></title></head><body style="background:transparant;">"];

    // Remove the iframe junk that wordpress has
    NSString *htmlText = [myArticle objectForKey:@"content"];
    NSRange range1 = [htmlText rangeOfString:@"<iframe"];
    NSRange range2 = [htmlText rangeOfString:@"</iframe>"];
    if (range1.location != NSNotFound && range2.location != NSNotFound) {
    htmlText = [NSString stringWithFormat:@"%@%@",
                [htmlText substringToIndex:range1.location],
                [htmlText substringFromIndex:(range2.location+range2.length)]];
    }


   // finish our html code
   [html appendString:htmlText];
   [html appendString:@"</body></html>"];

   //make the background transparent
   [webView setBackgroundColor:[UIColor clearColor]];

   NSURL *baseURL = [NSURL URLWithString:@"http://leimobile.com"];

   //pass the string to the webview
   [webView loadHTMLString:[html description] baseURL:baseURL];
}

Heres an example post
http://pastie.org/3161382 (Sorry, it would have been extremely ugly to post here)

Related posts

Leave a Reply

2 comments

  1. What about a VC with a WebView and then set the content of that WebView to your content element in the post? You could also add in your own custom CSS rules to format things the way you want them (like a tags, text size, etc).

  2. Follow these steps (assume you already create a tableView which works fine right)

    1) Create a ViewController with title, image and content dynamically. This way you can hide anything if you don’t have data for it.

    2) Use cellForRowAtIndexPath you know which cell got selected

    3) Use PushView to bring ViewController you create.

    4) Load all the values in it.