Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

BlogReader app - Showing the blog post in View Controller instead of UIWebView

Once I click on a blog post I want to show the post on the actual app instead of opening up the website through the WebView. How can I accomplish this?

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

There are two ways to accomplish it: open the link in safari or within your own app using UIWebView both of which are covered in the course. There is no third way to do it.

I'm talking about creating a DetailViewController adding a new View Controller in the Storyboard and linking it to the DetailViewController.

I have this code but I dont know what to change to make it work. (I get an error on upcomingReleasaesArray, I dont know what to add there.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    detailViewController.blogTitle = [[upcomingReleasesArray objectAtIndex.row] objectForKey:@"title"];
    [self.navigationController pushViewController:detailViewController animated:YES];
}

DetailViewController.h

@property (strong, nonatomic) NSDictionary *blogDetail;
@property (strong, nonatomic) IBOutlet UILabel *blogTitle;

My DetailViewController.m

@implementation DetailViewController

@synthesize blogDetail;
@synthesize blogTitle;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.blogTitle.text = [self.blogDetail objectForKey:@"title"];
}

I already imported DetailViewController to the TableView.

Thanks.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

There are a few issues with your code/project.

  • Did you create a new DetailViewController by adding it to the storyboard? If so, then this code will not work: DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; In this line the compiler is looking for a separate file called "DetailViewController. xib" and if you added your view controller to the storyboard then that file does not exist.

Go through this video on the Navigation Controller to learn how to add a detail view controller.

  • Is upcomingReleasesArray a property? Then you should refer to it as self. upcomingReleasesArray