0

I am currently using JSON to consume a web service.. here's the JSON:

[
{
id: 4,
title: "post1",
permalink: “http://www.example.com/test-post”,
content: “<html> >text here< <iframe src="//player.vimeo.com/video/1010101?title=0&amp;byline=0&amp;portrait=0&amp;color=ff5546" height="638" width="850" allowfullscreen="" frameborder="0"></iframe> <a href="http://example.com/wp-content/uploads/2014/01/testpic.png"><img class="aligncenter size-full wp-image-1180" alt="testpic" src="http://example.co/wp-content/uploads/2014/02/testpic.png" width="850" height="611" /></a>",
excerpt: " blah blah blah",
date: "2014-02-24 23:38:19",
author: "admin",
categories: 
[
"Uncategorized"
],
tags: [ ]
},
{
id: 1,
title: "Hello world!",
permalink: “http://www.example.com/test-post”,
content: "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!",
excerpt: "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!",
date: "2014-02-24 22:46:12",
author: "admin",
categories: 
[
"Uncategorized"
],
tags: [ ]
}
]

And here is the code I use:

#import "SecondViewController.h"
#import "AFNetworking.h"
#import "ThirdViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.jsonfeed = [[NSArray alloc] init];

    [self getJsonFeed];


    // 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.
}

-(void)getJsonFeed
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:@"http://example.com/feed/json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        self.jsonfeed = responseObject;
        [self.tableView reloadData];
        NSLog(@"%@", responseObject);

    } failure:nil];


}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [self.jsonfeed count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    NSDictionary *tempDictionary= [self.jsonfeed objectAtIndex:indexPath.row];
    cell.textLabel.text = [tempDictionary objectForKey:@"title"];

    return cell;
}

#pragma mark - Prepare For Segue

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    ThirdViewController *destinationViewController = (ThirdViewController *)segue.destinationViewController;
    destinationViewController.jsonData = [self.jsonfeed objectAtIndex:indexPath.row];

}

@end

I tried something like this:

NSString *myHTML = [NSString stringWithFormat:@"%@", _jsonData];
[webView loadHTMLString:myHTML baseURL:nil];

but I always get this error:

'[<ThirdViewController 0x8a265a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key storyboard.'

I've been stuck all day trying to figure it out..

Any suggestions?

1 Answers1

0

First i don't think your error has something to do with the webView, if you look here:

Error: this class is not key value coding-compliant for the key projectToolBar?

This guy had the same problem with connections at the story-bord.

Second, what i normally use to display html context, is the "RTLabel" class, very easy to use! and it works great!

https://github.com/honcheng/RTLabel

All you have to do is import: #import "RTLabel.h"

And use it like so:

          finalTakeTrhee = [NSString stringWithFormat:@"<font face='Helvetica-Light' size=15   color='black'>%@</font> ",finalTwo];
      }


    RTLabel *label = [[RTLabel alloc] initWithFrame:CGRectMake(90, 3, 236, 70)];
    label.tag = MY_CUSTOM_TAG;
    label.lineSpacing = -1;
    label.textAlignment = NSTextAlignmentLeft;

    [cell.contentView addSubview:label] ;

    //  [cell.contentView addSubview:label];
    [label setText:finalTakeTrhee];

Hope this helps

Community
  • 1
  • 1
MCMatan
  • 8,623
  • 6
  • 46
  • 85