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

Trent Burkenpas
Trent Burkenpas
22,388 Points

Can not connect storyboard to my custom class

Trying to connect custom class "FriendsViewController" to my storyboard. But, the class is not showing up with all the other custom classes. (if that makes any sense).

Video: http://teamtreehouse.com/library/build-a-selfdestructing-message-iphone-app-2/relating-users-in-parsecom/displaying-our-list-of-friends

Thanks !

22 Answers

Stone Preston
Stone Preston
42,016 Points

Try typing in the name of your class. You don't have to choose it in the drop down, you can type it in if it's not showing up. Sometimes closing the storyboard and reopening it or cleaning your project will fix it if it's not appearing, but I usually just type it in

I have the same problem! The friends list is empty but the console is showing that the code is retrieving a friends list, there are users in the list. Maybe something isn't hooked up right. Any suggestions?

Solved!

Trent Burkenpas
Trent Burkenpas
22,388 Points

Yeah I tried that, but the problem was that my friends were not showing up on my friends list in the ribbit app. So I figured that my "Friends" Table View was connected properly to my custom class. Maybe there is a error in my code. I think i'm going to just redo that part. Thanks for the help!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

If you're still stuck, paste in your view controller code and we'll help you get sorted out. :)

Trent Burkenpas
Trent Burkenpas
22,388 Points

Well out of pure frustration, i copy and paste all the code form the project file, and now i'm getting this error message

2014-01-28 17:34:00.579 Ribbit[8333:1303] Error: Error Domain=com.parse.networking.error Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x99d88d0 {NSErrorFailingURLKey=https://api.parse.com/2/user_login, NSLocalizedDescription=Expected status code in (200-299), got 401} (Code: 100, Version: 1.2.18)

it might be a issue with my storyboard ??

Thank you!

Trent Burkenpas
Trent Burkenpas
22,388 Points

Ok well this is funny! I decided to restart this project and i'm stuck on the same issue! Friends will not show up on the friends page.

Ben Jakuben here is my code for the FriendsViewController!

FriendsViewController.h

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface FriendsViewController : UITableViewController

@property (nonatomic, strong) PFRelation *friendsRelation;

@property (nonatomic, strong) NSArray *friends;

@end

FriendsViewController.m

#import "FriendsViewController.h"

@interface FriendsViewController ()

@end

@implementation FriendsViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    PFQuery *query = [self.friendsRelation query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
        }
    }];
}

#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.friends count];
}

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

    PFUser *user = [self.friends objectAtIndex:indexPath.row];
    cell.textLabel.text = user.username;

    return cell;
}





@end

Thank you so much!

Stone Preston
Stone Preston
42,016 Points

put an NSLog after your query is successful to log the users in your array. something like

else { self.friends = objects; [self.tableView reloadData]; NSLog(@"users in friends array: %@", self.friends; }

if the array is empty, somethings going on with your relation/query

if the array has data in it, something is going on with your table view delegate methods

Trent Burkenpas
Trent Burkenpas
22,388 Points

Hey Preston,

I tried what you suggested, but nothing showed up in the console. So could it be a issue with the friendsRelation queries?

Stone Preston
Stone Preston
42,016 Points

nothing at all? did you use this statement?

NSLog(@"users in friends array: %@", self.friends);

it should have at least printed something? make sure you select to show the console by clicking the icon on on the right side of the trash can in the debug view, I would click both the the icons so you show the console and the variables view.

Trent Burkenpas
Trent Burkenpas
22,388 Points

Hey Preston,

I tried what you suggested, but nothing showed up in the console. So could it be a issue with the friendsRelation queries?

Trent Burkenpas
Trent Burkenpas
22,388 Points

Yeah thats all open,
because i do see this "2014-02-06 16:50:44.790 Ribbit[10547:70b] Current user: Trent"

maybe i typed in something wrong??

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    PFQuery *query = [self.friendsRelation query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
            NSLog(@"users in friends array: %@",self.friends);
        }
    }];
}
Stone Preston
Stone Preston
42,016 Points

ok implement viewWillAppear and move all your friendsRelation code and query into that method instead of viewDidLoad

Trent Burkenpas
Trent Burkenpas
22,388 Points

ok, nothing happened. did i do it correctly?

- (void)viewDidLoad
{
    [super viewDidLoad];


}

-(void)viewWillAppear:(BOOL)animated {

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    PFQuery *query = [self.friendsRelation query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
            NSLog(@"users in friends array: %@",self.friends);
        }
    }];
}
Stone Preston
Stone Preston
42,016 Points

you forgot to call [super viewWillAppear:animated];

Trent Burkenpas
Trent Burkenpas
22,388 Points

ok I corrected my code, and I still do not see any changes

Stone Preston
Stone Preston
42,016 Points

hmm ok add an NSLog at the top of viewWillAppear something like NSLog(@"viewWillAppearCalled"); so we can see if that method is being called

Trent Burkenpas
Trent Burkenpas
22,388 Points

Ok, "viewDidAppearCalled" did show up in the console!

Stone Preston
Stone Preston
42,016 Points

ok now we are getting somewhere. It looks like you query isnt running. can you double check in the parse data browser if your PFUser class does indeed have a relation named friendsRelation associated with it?

Trent Burkenpas
Trent Burkenpas
22,388 Points

It does have a relation named friendsRelation

Stone Preston
Stone Preston
42,016 Points

can you click the relation for whatever user you log in as and view the friends in the data browser?

Stone Preston
Stone Preston
42,016 Points

interesting. place a log inside your query block but before the if/else block like so to see if the query is indeed running:

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        NSLog(@"query ran");
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
            NSLog(@"users in friends array: %@",self.friends);
        }
    }];
Trent Burkenpas
Trent Burkenpas
22,388 Points

ok, the NSLog did appear !

Stone Preston
Stone Preston
42,016 Points

ok so the query is running. try using this code (which basically is the opposite of what you currently have, just kind of switches the if/else around

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if(!error){

            self.friends = objects;
            [self.tableView reloadData];
            NSLog(@"friends: %@", self.friends);

        } else {

            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
Trent Burkenpas
Trent Burkenpas
22,388 Points

Hmmm that didn't change anything....debugging is the worst!

Stone Preston
Stone Preston
42,016 Points

man I really dont know whats going on. in your if/else print a log that says either @"error occurred" or @"success" depending on which block its in. that will tell you if your if/else blocks are being run.

Trent Burkenpas
Trent Burkenpas
22,388 Points

Ok, I tried that and I didn't get any of the logs in the console. Im think that the if/else isn't being run

Stone Preston
Stone Preston
42,016 Points

i really dont understand why. If anything that else should be running if there is an error. I really dont know what to tell you. Makes no sense

Trent Burkenpas
Trent Burkenpas
22,388 Points

Well Thank you for all the help. I think I just need to step away from this and come back to it later lol

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Whoa - sorry you're having all this trouble! I'm just now catching up on support in the Forum again after releasing my latest Android course. At this point, can you zip up your project and email it to help@teamtreehouse.com? If I can find anything I'll reply back in here.

Trent Burkenpas
Trent Burkenpas
22,388 Points

Wow you do both ios and Android? Which one do you prefer? lol Anyway thank you for the help, ill send it in as soon as I get a chance!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I love both but prefer Android! :smile: The concepts are very similar between the two, so it really comes down to getting comfortable with the language and APIs. Definitely check out the Android projects some time!

Trent Burkenpas
Trent Burkenpas
22,388 Points

cool I plan on learning both, just started with ios because i have a mac lol