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 trialBen Ford
2,499 PointsNo code in debugging area for Blog reader app
I have no code in my debugging area when I run the application and I have a problem that when I click on a blog post in the table view it just takes to me to a blank screen but in my code it should take me to the treehouse blog.
I have a feeling that these might both be connected? The reason I say this is because when Amit creates an NSLog for the segue between tableViewController and webViewController it creates the output in the debug area and I can't see anything!
If someone could help it would be much appreciated.
Ben Ford
2,499 PointswebViewController.m [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://blog.teamtreehouse.com"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL: url]; [self.webView loadRequest: urlRequest];
tableViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSLog(@"preparing for segue: %@", segue.identifier);
It will build successfully with no errors but in the simulator when I click to go through to the blog page it just comes up with a blank screen with a back button on the top left
2 Answers
Stone Preston
42,016 Pointscan you post all your code for your tableView controller?
Ben Ford
2,499 Points#import "TableViewController.h"
#import "BlogPost.h"
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *blogURL = [NSURL URLWithString: @"http://blog.teamtreehouse.com/api/get_recent_summary/"];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;
NSDictionary *dataDictioniary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
//NSLog(@"%@",dataDictioniary);
self.blogposts = [NSMutableArray array];
NSArray *blogPostsArray = [dataDictioniary objectForKey:@"posts"];
for (NSDictionary *bpDictionary in blogPostsArray) {
BlogPost * blogPost = [BlogPost BlogPostWithTitle: [bpDictionary objectForKey:@"title"]];
blogPost.author = [bpDictionary objectForKey:@"author"];
blogPost.Thumbnail = [bpDictionary objectForKey:@"thumbnail"];
blogPost.Date = [bpDictionary objectForKey:@"date"];
blogPost.url = [NSURL URLWithString:[bpDictionary objectForKey:@"url"]];
[self.blogposts addObject:blogPost];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.blogposts count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier forIndexPath:indexPath];
BlogPost *blogPost = [self.blogposts objectAtIndex:indexPath.row];
if ([blogPost.Thumbnail isKindOfClass:[NSString class]]) {
NSData *imageData = [NSData dataWithContentsOfURL:blogPost.thumbnailURL];
UIImage *image = [UIImage imageWithData:imageData];
cell.imageView.image = image;
} else {
cell.imageView.image = [UIImage imageNamed:@"House-Icon-for-Home-page.jpg"];
}
cell.textLabel.text = blogPost.Title;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@",blogPost.Author,blogPost.formattedDate];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"preparing for segue: %@", segue.identifier);
}
@end
Francisco Navarro
14,185 PointsIf the segue succeed I think the problem could be the webViewController.m Could you put all the code for that class as well? it seems some variable is nil as you are not getting errors
Gareth Borcherds
9,372 PointsGareth Borcherds
9,372 PointsCan you post some of your code for people to look at?