Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[help needed]: UITableview Cell to UIWebView

daniel_xxoxdaniel_xxox HullPosts: 1New Users Noob
edited January 2014 in iOS SDK Development
Hey everyone.

I was wondering whether you can help me with a problem that I am having? For the record I am very new to programming and if you could provide ' step by step dumbed down' answers I would be extremely grateful.

So, here goes. I am currently following this tutorial: and I have successfully finished it.

What I now would like to know is: How can I make each of the cells that are returned clickable with the url that is specified in the JSON feed so that they open a UIWebView? Also how, once the UIWebView is loaded would i make it so that you can switch back to the UITableView ?

Here is my complete .h file:

#import "ViewController.h"

// Define keys
static NSString *kTitleKey = @title;
static NSString *kThumbnailKey = @thumbnail;
static NSString *kAuthorKey = @author;
static NSString *kPermalinkKey = @permalink;

@interface ViewController ()
NSMutableArray *dataArray;

@implementation ViewController

- (void)viewDidLoad
[super viewDidLoad];
dataArray = [[NSMutableArray alloc] init];
NSData *jsonSource = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@""]];
id jsonObjects = [NSJSONSerialization JSONObjectWithData:
jsonSource options:0 error:nil];

for (NSDictionary *dataDict in jsonObjects) {
NSDictionary *dictionary = [dataDict dictionaryWithValuesForKeys:
@[kTitleKey, kThumbnailKey, kAuthorKey, kPermalinkKey]];
[dataArray addObject:dictionary];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return dataArray.count;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @Item;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell=[[UITableViewCell alloc]initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

NSDictionary *tmpDict = dataArray[indexPath.row];

NSString *text = tmpDict[kTitleKey];
if ([text isEqual:[NSNull null]]) {
text = @(empty);

NSString *author = tmpDict[kAuthorKey];
if ([author isEqual:[NSNull null]]) {
author = @(empty);
NSString *detail = [NSMutableString stringWithFormat:@Author: %@ ", author];

NSString *thumbnailURL = tmpDict[kThumbnailKey];
UIImage *img;
if ([thumbnailURL isEqual:[NSNull null]]) {
img = [UIImage imageNamed:@twitter-bg.png];
} else {
NSURL *url = [NSURL URLWithString:thumbnailURL];
NSData *data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];

cell.textLabel.text = text;
cell.detailTextLabel.text= detail;
cell.imageView.frame = CGRectMake(0, 0, 80, 70);
cell.imageView.image =img;

return cell;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString* launchUrl = dataArray[indexPath.row][kPermalinkKey];
NSLog(@URL: %@", launchUrl);
UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl;

- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];


Post edited by daniel_xxox on


Sign In or Register to comment.